How do i pull the number from this string "Emample_ColorRevA.Page1"
I want to be able to pull the number 1 using regular expressions, can someone assist me.
"Emample_ColorRevA.Page1" Result would be 1
"Emample_ColorRevB.Page2" Result would be 2
"Emample_ColorRevB.Page234" Result would be 234
How can I only get the number from the strings
Loading
Satish BhatPosted Aug 12, 2011, 2:03 AM
public static string GetNumberFromString(string input)
{
// To Match number anywhere in the string e.g. Something123And234
// you will get 123 & 234
// Match _match = Regex.Match(input.Trim(), @"[0-9]+");
// Match only at the end of the string
Match _match = Regex.Match(input.Trim(), @"(\d+)$");
return (_match.Value);
}
string _input = "Emample_ColorRevB.Page234";
string _output = GetNumberFromString(_input); // 234
David SmithPosted Aug 13, 2011, 5:51 PM
VulpesPosted Aug 13, 2011, 4:56 PM
If you uncheck mine and check his, then it should move the highlight to his post.
David SmithPosted Aug 13, 2011, 4:31 PM
VulpesPosted Aug 13, 2011, 12:58 PM
David SmithPosted Aug 13, 2011, 11:24 AM
David SmithPosted Aug 13, 2011, 11:22 AM
Satish BhatPosted Aug 13, 2011, 10:23 AM
Although I am a registered member since 2004, I made little contribution to the site because of whatever the reasons may be. Now because of you guys I am trying to participate whenever I find time. Keep up the good work.
Vuples, you are 100% right in "there's a tendency to always reach for the driver when an iron will do". So darnell follow the KISS design principle, use the solution and mark the answer.
VulpesPosted Aug 12, 2011, 2:27 PM
Don't forget to mark Satish's post as the accepted answer.
David SmithPosted Aug 12, 2011, 1:37 PM
you haven't explain vuples yet. lol
VulpesPosted Aug 12, 2011, 12:53 PM
The Regex.Match method says if there's a match in the string for the regular expression, then return it as a Match object. The Value property then gets the actual sub-string which is matched.
David SmithPosted Aug 12, 2011, 12:33 PM
Match _match = Regex.Match(input.Trim(), @"(\d+)$");
Start from "@"(\d+)$"
I understand the input.trim()
David SmithPosted Aug 12, 2011, 12:09 PM
VulpesPosted Aug 12, 2011, 11:17 AM
A good site for learning regular expressions from the ground up is this one:
http://www.regular-expressions.info/tutorial.html
David SmithPosted Aug 12, 2011, 11:13 AM
Also can someone point me to good sight using regular expressions
David SmithPosted Aug 12, 2011, 11:11 AM
Also can someone point me to good sight using regular expressions
David SmithPosted Aug 12, 2011, 11:11 AM
VulpesPosted Aug 12, 2011, 8:39 AM
Satish BhatPosted Aug 12, 2011, 7:51 AM
Suthish NairPosted Aug 12, 2011, 7:00 AM
VulpesPosted Aug 12, 2011, 4:32 AM