Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Search a string for a value?

Status
Not open for further replies.

JohnnyBGoode

Programmer
May 1, 2002
76
CA
I have a string "MyFile.doc". In the end, I would like ".doc". So, I would like to try to find the location of the ".", and then take the rest of the string. How can this be done?
 
Take a look at the Path class. You would do it like this:
Code:
String fileName = @"Myfile.doc";
String extension = Path.GetExtension(fileName);

It's unwise to write your own file/path handling functions, as you'd be unlikely to handle some of the stranger cases, such as UNC paths, and long Unicode paths (start with "/?///", IIRC, and are longer than MAX_PATH (255 characters))

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanx a bunch. But one more question...which "using" statement should I use so that the "Path.GetExtension" will be recognized?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top