String Parsing
-
Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark
-
Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark
You can create a pattern from starting and ending strings:
string start = "Setting"; string ending = "="; string pattern = Regex.Escape(start) + "([\w\W]*)" + Regex.Escape(ending);
Despite everything, the person most likely to be fooling you next is yourself.
-
Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark
You could also use Split
string splitParts[] = myString.split('=');
splitParts[0]
will be "Setting17"splitParts[1]
will be "50"Help me! I'm turning into a grapefruit! Buzzwords!
-
Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark