比如a= c:\qq.exe & vbcrlf & qq1.exe & vbcrlf & qq2.exe & vbcrlf
用什么方法在每个.exe后面都跟上一个vbcrlf,如果.exe后面有vbcrlf则不加。如果没有则加,在字符串尾只能留一个vbcrlf,这样怎么弄呀?
vb 去掉字符串的换行符
答案:2 悬赏:30 手机版
解决时间 2021-01-28 18:06
- 提问者网友:泪痣哥哥
- 2021-01-28 14:32
最佳答案
- 五星知识达人网友:鱼忧
- 2021-01-28 15:58
下面两种方案,你看看哪个是你想要的效果。要查看以下代码的效果,只需要把代码放入Form_Load即可
方案1:
Do While InStr(a, ".exe") <> 0
a = Replace(a, ".exe", ".eye" & vbCrLf)
Loop
Do While InStr(a, vbCrLf & vbCrLf) <> 0
a = Replace(a, vbCrLf & vbCrLf, vbCrLf)
Loop
Do While InStr(a, ".eye") <> 0
a = Replace(a, ".eye", ".exe")
Loop
MsgBox a
方案2:
Do While InStr(a, ".exe") <> 0
a = Replace(a, ".exe", ".eye & vbCrLf")
Loop
Do While InStr(a, " & vbCrLf & vbCrLf") <> 0
a = Replace(a, " & vbCrLf & vbCrLf", " & vbCrLf")
Loop
Do While InStr(a, ".eye") <> 0
a = Replace(a, ".eye", ".exe")
Loop
MsgBox a
方案1:
Do While InStr(a, ".exe") <> 0
a = Replace(a, ".exe", ".eye" & vbCrLf)
Loop
Do While InStr(a, vbCrLf & vbCrLf) <> 0
a = Replace(a, vbCrLf & vbCrLf, vbCrLf)
Loop
Do While InStr(a, ".eye") <> 0
a = Replace(a, ".eye", ".exe")
Loop
MsgBox a
方案2:
Do While InStr(a, ".exe") <> 0
a = Replace(a, ".exe", ".eye & vbCrLf")
Loop
Do While InStr(a, " & vbCrLf & vbCrLf") <> 0
a = Replace(a, " & vbCrLf & vbCrLf", " & vbCrLf")
Loop
Do While InStr(a, ".eye") <> 0
a = Replace(a, ".eye", ".exe")
Loop
MsgBox a
全部回答
- 1楼网友:不想翻身的咸鱼
- 2021-01-28 16:23
trim只能去除空字符,replace去除了所有的vbcrlf,要考虑保留字符串中间的vbcrlf,还要考虑字符串最后的换行符可能会有多个...如下是个思路:
function mytrim(byval s as string) as string
dim length as long
dim char as string
s = trim(s)
length = len(s) + 1
do
length = length - 1
char = mid(s, length, 1)
loop until char <> vbcr and char <> vblf
mytrim = mid(s, 1, length)
end function
'测试
private sub command1_click()
dim s as string
s = "abc" & vbcrlf & vbcrlf
debug.print mytrim(s); len(mytrim(s))
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯