I have the following string fromat:
session=11;reserID=1000001
How to get string array of number?
My code:
var value = "session=11;reserID=1000001";
var numbers = Regex.Split(value, @"^\d+");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You probably were on the right track but forgot the character class:
You can also write it shorter by using
\D+which is equivalent.However, you’d get an empty element at the start of the returned array, so caution when consuming the result. Sadly, Regex.Split() doesn’t have an option that removes empty elements (
String.Splitdoes, however). A not very pretty way of resolving that:based on the assumption that the semicolon is actually the relevant piece where you want to split.
Quick PowerShell test:
Another option would be to just skip the element: