vb中怎样把字符串中的多个空格合并成一个空格
5个回答
展开全部
Private Function MyTrim(s As String) As String
MyTrim = Trim(s) '去掉首尾空格
Do While InStr(1, MyTrim, " ") > 0 '循环直到检查到没有两个连续的空格
MyTrim = Replace(MyTrim, " ", " ")
Loop
End Function
Private Sub Command1_Click()
Dim s As String
s = " a b c d EEEEEEEE ewewe"
s = MyTrim(s)
MsgBox s
End Sub
MyTrim = Trim(s) '去掉首尾空格
Do While InStr(1, MyTrim, " ") > 0 '循环直到检查到没有两个连续的空格
MyTrim = Replace(MyTrim, " ", " ")
Loop
End Function
Private Sub Command1_Click()
Dim s As String
s = " a b c d EEEEEEEE ewewe"
s = MyTrim(s)
MsgBox s
End Sub
展开全部
Private Sub Command1_Click()
ReplaceDoubleSpace (Text1.Text)
End Sub
Private Function ReplaceDoubleSpace(ByVal str As String) As String
Dim r As String
r = Replace(str, Space(2), Space(1))
Dim m, n
Do
m = Len(r)
r = Replace(r, Space(2), Space(1))
n = Len(r)
Loop Until m = n
ReplaceDoubleSpace =r
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim s as string
If text1.text=" "+s then
Text1.text=" "
end if
其中text1是你想合并的
If text1.text=" "+s then
Text1.text=" "
end if
其中text1是你想合并的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
tmpstr = Trim(tmpstr ) '删除前后空格
tmpstr = Regex.Replace(tmpstr , "[\x20 ]{2,}", " ") ‘正则表达式替换中间连续空格为单个空格
tmpstr = Regex.Replace(tmpstr , "[\x20 ]{2,}", " ") ‘正则表达式替换中间连续空格为单个空格
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把两个替换成一个,循环多次
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询