怎样在字符串的指定位置插入空格.

ask999 2004-04-30 03:36:17
如:
Dim strCity as String
strCity="北京"
问题:
用什么函数可以在两个字中间插入一个空格.
...全文
641 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsftest 2004-04-30
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
s = "这是一个例子。"
l = Len(s)
For i = 2 To l * 2 Step 2
s = Left(s, i - 1) + Space(1) + Right(s, l - i / 2)
Next
s = Left(s, Len(s) - 1)
Print s
Print Len(s)
End Sub
hhyttppd 2004-04-30
  • 打赏
  • 举报
回复
这并不是一项基本操作,VB好像没有。不过可以这样:
function InsetNChar(byref strS as string,byval intI as integer,byval chrC as byte,byval intNum as integer) as integer
'==========================================
strs 要操作的字符串
intI 插入位置
chrC 插入的字符
intNum 插入的个数
'================
返回:1 :操作正确
0 :错误
'=========================================
dim tempS as string
dim leftS as string,rightS as string
dim lenS as integer
lenS=len(strS)
if intI>lens then
InsertNchar=0
exit sub
end if
leftS=left(strS,intI)
rightS=right(strS,lenb(strS)-intI)
tempS=leftS+trim(string(chrC,intNum))+rightS
strS=tempS
InsertNchar=1
end function

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧