parsing a string
-
I'm brand new to C# and I'm trying to figure out how to parse a string. Is there a function available much like the explode() function in PHP which breaks up the string on a certain character and places the different parts into an array?
string s = "a,b,c"; string[] parsed = s.Split(','); Darryl Borden Principal IT Analyst dborden@eprod.com
-
I'm brand new to C# and I'm trying to figure out how to parse a string. Is there a function available much like the explode() function in PHP which breaks up the string on a certain character and places the different parts into an array?
Well, one thing I'm doing is this. I have a String variable called 'filename' which contains the entire path and filename, including extension. I want just the filename, no directories or extensions. To do this, I have this one command:
String shortened = Filename.Substring(Filename.LastIndexOf("\\") + 1, Filename.LastIndexOf(".") - Filename.LastIndexOf("\\") - 1);
LastIndexOf() figures out the number position of the last one of that kind of character. Substring() extracts out n number of characters starting at position m, where the arguments are .Substring(m, n) C# isn't meant to parse out strings like PHP, PERL and others but I think you can find quite suitable alternatives using those methods and possibly others.