VB.NET取得字符串中所有的数字:
1.用正则表达式:
'引入命名空间 Imports System.Text.RegularExpressions Public Shared Function GetNumbers(ByVal str As String) As String Return Regex.Replace(str,"[a-z]","",RegexOptions.IgnoreCase).Trim() End Function
2.写一个函数
''' <summary> ''' 从字符串中提取所有数字 ''' Returns:所有数字 ''' </summary> ''' <param name = "strp">需要提取的字符串 </param> ''' <returns> 所有数字</returns> Private Function GetNumbers(ByVal strp As String) As String Dim strReturn As String = String.Empty If strp Is Nothing OrElse strp.Trim() = "" Then strReturn = "" End If For Each chrTemp As Char In strp If [Char].IsNumber(chrTemp) Then strReturn += chrTemp.ToString() End If Next Return strReturn End Function原文链接:https://www.f2er.com/vb/257824.html