- Get link
- X
- Other Apps
Posted by
Real
- Get link
- X
- Other Apps
In interview often it is asked by candidate to test his ability of data type.
Q: How you will get all the numbers from given string.
Ans: for this let's say string is "Anand123". We will use regex as a best option.
code:
string stringToExtract = "Anand123";
result = Int32.Parse(Regex.Match(stringToExtract, @"\d+").Value);
Output: 123
And this is all we have to do.
Comments
Post a Comment
Thanking you for the comment.