4个回答
展开全部
这个要用到字符串处理函数,如Len、left、right、mid、instr、instrrev、replace等等,发现一楼也说了很多,下面我用例子讲几个函数的用法,
Private Sub Command1_Click()
Dim temp As String '源字符串
Dim temp2 As String '要插入的字符串
Dim temp3 As String '要插入的字符串的左边所有字符串
Dim temp4 As String '要插入的字符串的右边所有字符串
Dim star As Integer '字符插入的位置
Dim LenStr As Integer '字符的长度
star = 2
temp2 = "不"
temp = "我爱你"
Print "temp=" & temp
LenStr = Len(temp)
Print "LenStr=" & LenStr
temp3 = Left(temp, star - 1) '从左起,截取star - 1长度的字符串
Print "temp3=" & temp3
temp4 = Right(temp, LenStr - star + 1) '从右起,截取LenStr - star + 1长度的字符串
Print "temp4=" & temp4
temp = temp3 & temp2 & temp4
Print "temp=" & temp
temp = Replace(temp, "不", "", , , vbTextCompare) '替换"不"为"",可以起到删除"不"的作用
Print "temp=" & temp
End Sub
蓦然回首,发现已经选出满意答案了,这么快啊!!!
Private Sub Command1_Click()
Dim temp As String '源字符串
Dim temp2 As String '要插入的字符串
Dim temp3 As String '要插入的字符串的左边所有字符串
Dim temp4 As String '要插入的字符串的右边所有字符串
Dim star As Integer '字符插入的位置
Dim LenStr As Integer '字符的长度
star = 2
temp2 = "不"
temp = "我爱你"
Print "temp=" & temp
LenStr = Len(temp)
Print "LenStr=" & LenStr
temp3 = Left(temp, star - 1) '从左起,截取star - 1长度的字符串
Print "temp3=" & temp3
temp4 = Right(temp, LenStr - star + 1) '从右起,截取LenStr - star + 1长度的字符串
Print "temp4=" & temp4
temp = temp3 & temp2 & temp4
Print "temp=" & temp
temp = Replace(temp, "不", "", , , vbTextCompare) '替换"不"为"",可以起到删除"不"的作用
Print "temp=" & temp
End Sub
蓦然回首,发现已经选出满意答案了,这么快啊!!!
展开全部
插入一个字符:
Dim a As String, b As String
a = "IYou"
b = " LOVE "
a = Left(a, 1) & b & Right(a, 3)
MsgBox a
删除一个字符:
Dim a As String
a = "I LOVE You"
a = Left(a, 4) & Right(a, 3)
MsgBox a
Dim a As String, b As String
a = "IYou"
b = " LOVE "
a = Left(a, 1) & b & Right(a, 3)
MsgBox a
删除一个字符:
Dim a As String
a = "I LOVE You"
a = Left(a, 4) & Right(a, 3)
MsgBox a
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mid
left
right
len
replace
弄清楚这几个函数应该差不多了吧。一时想不起太多。
left
right
len
replace
弄清楚这几个函数应该差不多了吧。一时想不起太多。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
strtest="123456"
for i = 1 to len(strtest)
if i mod 2 = 0 then
strnew=strnew & mid(strtest,i,1)
end if
next
自行扩展
for i = 1 to len(strtest)
if i mod 2 = 0 then
strnew=strnew & mid(strtest,i,1)
end if
next
自行扩展
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询