本文链接:https://blog.csdn.net/fengqingtao2008/article/details/38943171
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
————————————————
版权声明:本文为CSDN博主「Json2008」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/fengqingtao2008/article/details/38943171
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |