Skip to content

Numerical from String

nzh

Asked Dec 11, 2006, 10:00 PM EST1 answer
Share
LinkedInX
Hi everyone 
VB.NET
If i create a string object, how can i take the numerical value in this string object? Is there an easy method of string class?
For example:

String myString;
myString = "sth389";
int ab = myString.XXX ;
 
I want the value of  "ab" to be 389 here.
Any suggestions?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can use a regular expression to do that.

    using System.Text.RegularExpressions;

    int i = Convert.ToInt32(Regex.Replace("birseyler389", "[^0-9]", ""));
    0