a = "£123"
怎么把123提取出来
我用replace(a,"£","")
硬是没用 郁闷
10 个解决方案
#1
按照你的方法,只需要再用val、int或者clng中的任何一个函数对a再进行一次运算就行了
#2
a = replace(a,"£","")
#3
dim b as long
b=clng(replace(a,"£",""))
用replace可以啊
b=clng(replace(a,"£",""))
用replace可以啊
#4
使用正则表达式,事例如下:
Option Explicit
Private Sub Form_Load()
Debug.Print (TestRegExp("\d+?", "ad23sf$123ad45fa"))
End
End Sub
Function TestRegExp(myPattern As String, myString As String) As String
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String
Set objRegExp = New RegExp
objRegExp.Pattern = myPattern
objRegExp.IgnoreCase = True
objRegExp.Global = True
If (objRegExp.Test(myString) = True) Then
Set colMatches = objRegExp.Execute(myString)
For Each objMatch In colMatches
RetStr = RetStr & objMatch.Value
Next
Else
RetStr = "String Matching Failed"
End If
TestRegExp = RetStr
End Function
Option Explicit
Private Sub Form_Load()
Debug.Print (TestRegExp("\d+?", "ad23sf$123ad45fa"))
End
End Sub
Function TestRegExp(myPattern As String, myString As String) As String
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String
Set objRegExp = New RegExp
objRegExp.Pattern = myPattern
objRegExp.IgnoreCase = True
objRegExp.Global = True
If (objRegExp.Test(myString) = True) Then
Set colMatches = objRegExp.Execute(myString)
For Each objMatch In colMatches
RetStr = RetStr & objMatch.Value
Next
Else
RetStr = "String Matching Failed"
End If
TestRegExp = RetStr
End Function
#5
怎么会?
你是不是没有接受返回值?
dim b as string
b = replace(a, "£", "")
你是不是没有接受返回值?
dim b as string
b = replace(a, "£", "")
#6
'写了个函数,没有调试,不知道行不行
function getNumFromStr(byval str1 as string) as double
if isnumeric(str1) then
getNumFromStr = CDbl(str1)
exit function
end if
dim lngLen as Long
lngLen = len(str1)
do while not isnumeric(str1)
lngLen = lngLen - 1
if lngLen = 0 then
msgbox "不包含数字"
exit function
end if
str1 = right(str1,lngLen)
loop
getNumFromStr = val(str1)
end function
function getNumFromStr(byval str1 as string) as double
if isnumeric(str1) then
getNumFromStr = CDbl(str1)
exit function
end if
dim lngLen as Long
lngLen = len(str1)
do while not isnumeric(str1)
lngLen = lngLen - 1
if lngLen = 0 then
msgbox "不包含数字"
exit function
end if
str1 = right(str1,lngLen)
loop
getNumFromStr = val(str1)
end function
#7
晕,好像不行,如果后面有非数字字符,用isnumeric是没法判断出来的
#8
a = replace(a,"£","")
我知道的 没用
说错了 不是string
是用split函数得到的字符流
a=split(xxx)
这个时候a(0)的值 "£5.55"
用了 上面说的 函数 都没用 :(
我觉得很奇怪 £的ansi码>163的 现在在txt文本中竟然能显示出来 郁闷
可能就是这个问题 replace函数无效
我知道的 没用
说错了 不是string
是用split函数得到的字符流
a=split(xxx)
这个时候a(0)的值 "£5.55"
用了 上面说的 函数 都没用 :(
我觉得很奇怪 £的ansi码>163的 现在在txt文本中竟然能显示出来 郁闷
可能就是这个问题 replace函数无效
#9
Option Explicit
Private Sub Command1_Click()
MsgBox IsNum(Text1.Text)
End Sub
Private Function IsNum(ByVal Text As String) As String
Dim i As Long
Dim Ret As String
For i = 1 To Len(Text)
If InStr(1, "0123456789", Mid(Text, i, 1)) Then Ret = Ret & Mid(Text, i, 1)
Next
IsNum = Ret
End Function
Private Sub Command1_Click()
MsgBox IsNum(Text1.Text)
End Sub
Private Function IsNum(ByVal Text As String) As String
Dim i As Long
Dim Ret As String
For i = 1 To Len(Text)
If InStr(1, "0123456789", Mid(Text, i, 1)) Then Ret = Ret & Mid(Text, i, 1)
Next
IsNum = Ret
End Function
#10
:)
感谢楼上各位
dim string a
a=text1.text
a=replace(a,"£","")
text1.text=a
就可以了
-____________-
但text1.text=replace(text1.text,"£",")
就是不行 我郁闷哦
感谢楼上各位
dim string a
a=text1.text
a=replace(a,"£","")
text1.text=a
就可以了
-____________-
但text1.text=replace(text1.text,"£",")
就是不行 我郁闷哦
#1
按照你的方法,只需要再用val、int或者clng中的任何一个函数对a再进行一次运算就行了
#2
a = replace(a,"£","")
#3
dim b as long
b=clng(replace(a,"£",""))
用replace可以啊
b=clng(replace(a,"£",""))
用replace可以啊
#4
使用正则表达式,事例如下:
Option Explicit
Private Sub Form_Load()
Debug.Print (TestRegExp("\d+?", "ad23sf$123ad45fa"))
End
End Sub
Function TestRegExp(myPattern As String, myString As String) As String
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String
Set objRegExp = New RegExp
objRegExp.Pattern = myPattern
objRegExp.IgnoreCase = True
objRegExp.Global = True
If (objRegExp.Test(myString) = True) Then
Set colMatches = objRegExp.Execute(myString)
For Each objMatch In colMatches
RetStr = RetStr & objMatch.Value
Next
Else
RetStr = "String Matching Failed"
End If
TestRegExp = RetStr
End Function
Option Explicit
Private Sub Form_Load()
Debug.Print (TestRegExp("\d+?", "ad23sf$123ad45fa"))
End
End Sub
Function TestRegExp(myPattern As String, myString As String) As String
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String
Set objRegExp = New RegExp
objRegExp.Pattern = myPattern
objRegExp.IgnoreCase = True
objRegExp.Global = True
If (objRegExp.Test(myString) = True) Then
Set colMatches = objRegExp.Execute(myString)
For Each objMatch In colMatches
RetStr = RetStr & objMatch.Value
Next
Else
RetStr = "String Matching Failed"
End If
TestRegExp = RetStr
End Function
#5
怎么会?
你是不是没有接受返回值?
dim b as string
b = replace(a, "£", "")
你是不是没有接受返回值?
dim b as string
b = replace(a, "£", "")
#6
'写了个函数,没有调试,不知道行不行
function getNumFromStr(byval str1 as string) as double
if isnumeric(str1) then
getNumFromStr = CDbl(str1)
exit function
end if
dim lngLen as Long
lngLen = len(str1)
do while not isnumeric(str1)
lngLen = lngLen - 1
if lngLen = 0 then
msgbox "不包含数字"
exit function
end if
str1 = right(str1,lngLen)
loop
getNumFromStr = val(str1)
end function
function getNumFromStr(byval str1 as string) as double
if isnumeric(str1) then
getNumFromStr = CDbl(str1)
exit function
end if
dim lngLen as Long
lngLen = len(str1)
do while not isnumeric(str1)
lngLen = lngLen - 1
if lngLen = 0 then
msgbox "不包含数字"
exit function
end if
str1 = right(str1,lngLen)
loop
getNumFromStr = val(str1)
end function
#7
晕,好像不行,如果后面有非数字字符,用isnumeric是没法判断出来的
#8
a = replace(a,"£","")
我知道的 没用
说错了 不是string
是用split函数得到的字符流
a=split(xxx)
这个时候a(0)的值 "£5.55"
用了 上面说的 函数 都没用 :(
我觉得很奇怪 £的ansi码>163的 现在在txt文本中竟然能显示出来 郁闷
可能就是这个问题 replace函数无效
我知道的 没用
说错了 不是string
是用split函数得到的字符流
a=split(xxx)
这个时候a(0)的值 "£5.55"
用了 上面说的 函数 都没用 :(
我觉得很奇怪 £的ansi码>163的 现在在txt文本中竟然能显示出来 郁闷
可能就是这个问题 replace函数无效
#9
Option Explicit
Private Sub Command1_Click()
MsgBox IsNum(Text1.Text)
End Sub
Private Function IsNum(ByVal Text As String) As String
Dim i As Long
Dim Ret As String
For i = 1 To Len(Text)
If InStr(1, "0123456789", Mid(Text, i, 1)) Then Ret = Ret & Mid(Text, i, 1)
Next
IsNum = Ret
End Function
Private Sub Command1_Click()
MsgBox IsNum(Text1.Text)
End Sub
Private Function IsNum(ByVal Text As String) As String
Dim i As Long
Dim Ret As String
For i = 1 To Len(Text)
If InStr(1, "0123456789", Mid(Text, i, 1)) Then Ret = Ret & Mid(Text, i, 1)
Next
IsNum = Ret
End Function
#10
:)
感谢楼上各位
dim string a
a=text1.text
a=replace(a,"£","")
text1.text=a
就可以了
-____________-
但text1.text=replace(text1.text,"£",")
就是不行 我郁闷哦
感谢楼上各位
dim string a
a=text1.text
a=replace(a,"£","")
text1.text=a
就可以了
-____________-
但text1.text=replace(text1.text,"£",")
就是不行 我郁闷哦