分割字符串,请教各位,谢谢!!!
我想取得字符串里面最后的数字(不包含夹在字符里面的数字)
4fdde3 分割后为 4fdde和3
fd3d33 分割后为 fd3d和33
rte43re433 分割后为 rte43re和433
谢谢!!!
[解决办法]
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim s() As String = {"4fdde3", "fd3d33", "rte43re433"}
For Each i As String In s
Dim m As Match = Regex.Match(i, "(.+?)(\d+)")
Console.WriteLine("{0} 分割后为 {1} 和 {2}", i, m.Groups(1).Value, m.Groups(2).Value)
Next
End Sub
End Module
4fdde3 分割后为 4fdde 和 3
fd3d33 分割后为 fd 和 3
rte43re433 分割后为 rte 和 43
Press any key to continue . . .
[解决办法]
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim s() As String = {"4fdde3", "fd3d33", "rte43re433"}
For Each i As String In s
Dim m As Match = Regex.Match(i, "(.+?)(\d+$)")
Console.WriteLine("{0} 分割后为 {1} 和 {2}", i, m.Groups(1).Value, m.Groups(2).Value)
Next
End Sub
End Module
4fdde3 分割后为 4fdde 和 3
fd3d33 分割后为 fd3d 和 33
rte43re433 分割后为 rte43re 和 433
Press any key to continue . . .
[解决办法]
整天编出这种课堂练习题有什么意思啊?多做点产品开发中的设计吧!
[解决办法]
试试如下的代码,可以改写为过程。
'str_oldstring为要处理的字符串
Dim str_oldstring = "adfasdf357q454"
Dim str_shuzi As String = "", str_zimu As String = ""
For i = 0 To Len(str_oldstring) - 1
If Not Mid(str_oldstring, Len(str_oldstring) - i, 1) Like "[0-9]" Then
Exit For
End If
str_shuzi = Mid(str_oldstring, Len(str_oldstring) - i, 1) + str_shuzi
Next
str_zimu = str_oldstring.Replace(str_shuzi, "")
'str_shuzi为数字部分
'str_zimu为前面的字母部分