Ber*_*eer 2 string vb6 replace
好吧,我做了我的研究,并看到了很多关于此的帖子,但无法在VB6中找到解决方案, 所以我怎么能在VB6中做到这一点?
让我说我得到一个字符串:
"曾几何时,有一个小孩想要1000远离家乡远离......"
我想只从字符串中分离出这个字符串中的数字 " 1000"并想要替换整个字符串,但数字应该保持不变.
最简单的方法是遍历字符串并将数字复制到新的数字:
Function GetNumbers(Value As String) As String
Dim Index As Long
Dim Final As String
For Index = 1 To Len(Value)
If Mid(Value, Index, 1) Like "[0-9]" Then
Final = Final & Mid(Value, Index, 1)
End If
Next
GetNumbers = Final
End Function
Run Code Online (Sandbox Code Playgroud)
结果:
?GetNumbers("abc12def345")
12345
Run Code Online (Sandbox Code Playgroud)
当有很多数字时,这对于长字符串是低效的.
| 归档时间: |
|
| 查看次数: |
4702 次 |
| 最近记录: |