4 Replies - 589 Views - Last Post: 16 November 2012 - 11:44 AM Rate Topic: -----

#1 Stephen68  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 08-April 11

Getting first two letters of a file name with getfiles

Posted 16 November 2012 - 08:10 AM

Hello...

I'm using getfiles() to help me grab all the files of a type from a directory. I have a combobox
that lets a user pick the first two letter of the file name. The problem I'm having is that some
files have upper case for first two chars some have lower case or a combination of both. So I was
wondering if somebody could point me in the direction on where I can find out how to make the first
2 chars upper.

Here is the code I'm using in the getfiles()

 fileNames = Directory.GetFiles(dirLocation, product.SelectedItem + ".rlt");




Thanks for your time in helping me

Stpehen

Is This A Good Question/Topic? 0
  • +

Replies To: Getting first two letters of a file name with getfiles

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9098
  • View blog
  • Posts: 34,184
  • Joined: 12-June 08

Re: Getting first two letters of a file name with getfiles

Posted 16 November 2012 - 08:21 AM

You know the string namespace has a 'to upper' and 'to lower' method, right? Combine that with the substring method and you should be there (assuming you convert your user's input into a similar fashion of 'to upper' or 'to lower').

<string name>.Substring(0, 2).ToUpper()

Was This Post Helpful? 1
  • +
  • -

#3 AthenaDX  Icon User is offline

  • D.I.C Regular

Reputation: 101
  • View blog
  • Posts: 307
  • Joined: 26-October 12

Re: Getting first two letters of a file name with getfiles

Posted 16 November 2012 - 08:22 AM

http://support.microsoft.com/kb/312890

Is this what you're looking for? Converting to uppercase?

Edit: Darn that Modi and beatin' me to it. ^_^

This post has been edited by AthenaDX: 16 November 2012 - 08:23 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3556
  • View blog
  • Posts: 11,027
  • Joined: 05-May 12

Re: Getting first two letters of a file name with getfiles

Posted 16 November 2012 - 10:56 AM

If you are running on a Windows platform, the Directory.GetFiles() is going to be case insensitive anyway, so it doesn't matter if product.SelectedItem is upper case, lower case, or some combination of upper and lower case.
Was This Post Helpful? 0
  • +
  • -

#5 Stephen68  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 08-April 11

Re: Getting first two letters of a file name with getfiles

Posted 16 November 2012 - 11:44 AM

Ya just found this out thanks for the good info. guys
My big problem was I had to down wrong, it was

fileNames = Directory.GetFiles(dirLocation, product.SelectedItem + ".rlt");



and it should of been

fileNames = Directory.GetFiles(dirLocation, product.SelectedItem + "*.rlt");




again thanks so much for your input, I read the link and learned something as well.

Cheers!
Stephen
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1