Extracting a Digit from any Alpha-Numeric string.

vishalneeraj-24503
Posted by vishalneeraj-24503 under VB.NET category on | Points: 40 | Views : 366
1st way:-
Public Function Extract_Digit_From_AlphaNumeric_String1(ByVal str_val As String) As String
Return String.Join(Nothing, Regex.Split(str_val, "[^\d]"))
End Function


2nd way:-
Public Function Extract_Digit_From_AlphaNumeric_String2(ByVal str_val As String) As String
Return New [String](str_val.ToCharArray().Where(Function(c) [Char].IsDigit(c)).ToArray())
End Function


3rd way:-
Public Function Extract_Digit_From_AlphaNumeric_String3(ByVal str_val As String) As String
Return New [String](str_val.Where(Function(c) [Char].IsDigit(c)).ToArray())
End Function


To test,take a dummy value containing alpha-numeric values as:-
Response.Write(Extract_Digit_From_AlphaNumeric_String1("A1abc1sdc$sgdb234bi90867as679998Z") + "<br/>")
Response.Write(Extract_Digit_From_AlphaNumeric_String2("A1abc1sdc$sgdb234bi90867as679998Z") + "<br/>")
Response.Write(Extract_Digit_From_AlphaNumeric_String3("A1abc1sdc$sgdb234bi90867as679998Z") + "<br/>")


Output:-
1123490867679998
1123490867679998
1123490867679998

Comments or Responses

Login to post response