-2
A
回答
-1
尝试
strString = "Smith"
strleng=Len(strString)
result=""
if strleng<2 then
result=strString
else
For i=1 To strleng
result= result& Mid(strString,i,1)
if i<>strleng then
result= result& "_"
end if
Next
end if
-1
或者:
Option Explicit
' string concatenation (bad idea in languages with non-mutable strings)
Function f1(s)
Dim l : l = Len(s)
If 2 > l Then
f1 = s
Else
Dim p
f1 = Left(s, 1)
For p = 2 To l
f1 = f1 & "_" & Mid(s, p, 1)
Next
End If
End Function
' Array via Mid(), Join
Function s2a(s)
Dim l : l = Len(s)
ReDim a(l - 1)
Dim p
For p = 1 To l
a(p - 1) = Mid(s, p, 1)
Next
s2a = a
End Function
Function f2(s)
f2 = Join(s2a(s), "_")
End Function
' RegExp.Replace, Mid(,2) to get rid of first _
Function f3(s)
Dim r : Set r = New RegExp
r.Global = True
r.Pattern = "(.)"
f3 = Mid(r.Replace(s, "_$1"), 2)
End Function
Function qq(s)
qq = """" & s & """"
End Function
Dim s, t
For Each s In Split(" a ab abc abcd Smith")
WScript.Echo "-----", qq(s)
t = f1(s)
WScript.Echo " ", qq(t)
t = f2(s)
WScript.Echo " ", qq(t)
t = f3(s)
WScript.Echo " ", qq(t)
Next
输出:
cscript 39814484.vbs
----- ""
""
""
""
----- "a"
"a"
"a"
"a"
----- "ab"
"a_b"
"a_b"
"a_b"
----- "abc"
"a_b_c"
"a_b_c"
"a_b_c"
----- "abcd"
"a_b_c_d"
"a_b_c_d"
"a_b_c_d"
----- "Smith"
"S_m_i_t_h"
"S_m_i_t_h"
"S_m_i_t_h"
相关问题
- 1. 将字符串转换特殊字符
- 2. 将字符串添加到字符串
- 3. 手动添加特殊字符到pdf
- 4. 使用jQuery向字符串添加特殊字符
- 5. 通过PropertyGrid向字符串属性添加特殊字符
- 6. 将字符添加到字符串
- 7. 将字符添加到字符串
- 8. Python - 将字符添加到字符串
- 9. 将字符添加到字符串
- 10. 将字符添加到JSON字符串
- 11. 将字符添加到字符串vb.net
- 12. Java将字符添加到字符串
- 13. 修剪字符串以添加特殊字符和数字字符
- 14. PHP - 将字符串添加到特定字符位置的现有字符串
- 15. 基于字符计数将字符串添加到字符串
- 16. 字符串附加到文件转换为特殊字符
- 17. 将带有特殊字符的字符串插入到RTF中
- 18. 特殊字符#在一个字符串
- 19. 用特殊字符替换字符串
- 20. 写特殊字符在bash字符串
- 21. 特殊字符转换字符串
- 22. Preapre字符串包含特殊字符
- 23. 用特殊字符分割字符串
- 24. javascript字符串中的特殊字符
- 25. xslt字符串中的特殊字符
- 26. 特殊字符和Java字符串
- 27. 用特殊字符打印字符串
- 28. 字符串中的Python特殊字符
- 29. 将字符串添加到逐字字符串文字
- 30. 将字符串添加到字符串的数字和数字
为什么-1?此代码工作! – Esperento57