向指定位置插入字符

hjxxx 2005-12-30 05:23:15
'Insert(Str,Position,InString) 向指定位置插入字符
'Str 原始字段
'Position 位置
'InString 要插入的字符串
function Insert(Str,Position,InString)
SI=len(Str)
for i=1 to SI
hStr=hStr&left(Str,1)
Str=right(Str,(SI-i))
if i mod Position=0 then hStr=hStr&InString
next
Insert=hStr
end function
上面我写的,目的和标题一样。当然,我要处理的字符串不大(255以内)。

如果处理很长串字符的话肯定不行,不晓得有没好点的方法。
asp的!
...全文
77 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjxxx 2005-12-30
  • 打赏
  • 举报
回复
如果插入点为3,则将会在原字符串的3、6、9……处插入
yuanrong 2005-12-30
  • 打赏
  • 举报
回复
重复插入?没明白。
hjxxx 2005-12-30
  • 打赏
  • 举报
回复
忘了说明一点,
就是可以重复插入
if i mod Position=0 then hStr=hStr&InString
楼上的只可以插入一次
yuanrong 2005-12-30
  • 打赏
  • 举报
回复
随便写了一个,好像没问题.你看看

<%
Function InsertChar(str1,p,str2)

InsertChar = Left(str1,p - 1) & str2 & Right(str1,Len(str1) - (p - 1))

End Function

Response.Write(InsertChar("1234567ertettrtetertpoekrtkeprtkpeorkptoekrtpkerptkperktpoerktpoekrtpkepktpeoktpeorktetert",20,"我的天空"))
%>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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