请教一个关于ASP字符串的小问题

来源:百度知道 编辑:UC知道 时间:2024/05/01 05:26:26
现在有字符串“测试字符”
怎样在字符串中第三个和第四个字符中间 添加字符串“呵呵”?

<%
'str原始字符串
'start要插入字符串的位置
'insStr要插入的字符串
function InsertStr(str,start,insStr)
if start<=len(str) then
InsertStr=left(str,start-1)& insStr & mid(str,start)
end if
end function

s1="测试字符"
response.Write(InsertStr(s1,4,"呵呵"))
%>

先取出前三个,再连接"呵呵",再连接右侧剩下的
left("测试字符",3)&"呵呵"&right("测试字符",len("测试字符")-3)