Get only numbers from string

前端 未结 8 541
耶瑟儿~
耶瑟儿~ 2021-01-01 15:37

i want to get only numbers from string.

Lest say that this is my string :

324ghgj123

i want to get:

324123
相关标签:
8条回答
  • 2021-01-01 16:14

    For a linear search approach you can use this algorithm, it’s in C# but can easily be translated in vb.net, hope it helps.

    string str = “123a123”;
    
    for(int i=0;i<str.length()-1;i++)
    {
        if(int.TryParse(str[i], out nval))
            continue;
        else
            str=str.Rremove(i,i+1);
    }
    
    0 讨论(0)
  • 2021-01-01 16:19

    Function that returns string without digits

    Public Function _RemoveNonDigitCharacters(S As String) As String
            Return New String(S.Where(Function(x As Char) System.Char.IsDigit(x)).ToArray)
    End Function
    
    0 讨论(0)
提交回复
热议问题