如果字串中有數字,想取出字串中的數字的話,可使用下列方式
如果字串中有數字,想取出字串中的數字的話,可使用下列方式:
1 Dim str As String = "abc123def"
2 Dim str2 As String = Regex.Replace(Str, "[^0-9_]*", "")
2 Dim str2 As String = Regex.Replace(Str, "[^0-9_]*", "")
Str2會等於123
但如果為下列形式字串,則會把數字都黏在一起,要注意!
1 Dim str As String = "abc123def456ghi"
2 Dim str2 As String = Regex.Replace(Str, "[^0-9_]*", "")
2 Dim str2 As String = Regex.Replace(Str, "[^0-9_]*", "")
Str2會等於123456