Extracting a Character string from any Alpha-Numeric string.

vishalneeraj-24503
Posted by vishalneeraj-24503 under VB.NET category on | Points: 40 | Views : 367
1ST WAY:-
Public Function Extract_String_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_String_From_AlphaNumeric_String2(ByVal str_val As String) As String
Return New [String](str_val.ToCharArray().Where(Function(c) [Char].IsLetter(c)).ToArray())
End Function

3RD WAY:-
Public Function Extract_String_From_AlphaNumeric_String3(ByVal str_val As String) As String
Return New [String](str_val.Where(Function(c) [Char].IsLetter(c)).ToArray())
End Function


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

Output:-
Aabcsdc$sgdbbiasZ
AabcsdcsgdbbiasZ
AabcsdcsgdbbiasZ

Comments or Responses

Login to post response