怎么循环给字符串加空格?

retrieve 2003-09-11 04:35:39
比如
str = "是宽度分散积分飞机大负担爱戴积分为了电话打开换行"
而我想要的是
str = "是宽度 分散积 分飞机 大负担 爱戴积 分为了 电话打 开换行"

怎么得到?
...全文
116 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudchen 2003-09-11
  • 打赏
  • 举报
回复
str = "是宽度分散积分飞机大负担爱戴积分为了电话打开换行"
For i = 1 to len(str) step 3
result = result & mid(str,i,3)&" "
Next
response.write result
KUMOZAKI 2003-09-11
  • 打赏
  • 举报
回复
不好意思,搞错了,for语名应该是两个换一换位置!

......
for i=1 to len(str)
for j=1 to 118 '如果您想查到英文为止,我记得大Z是118
if instr(str,i)=chr(j) then
......
KUMOZAKI 2003-09-11
  • 打赏
  • 举报
回复
其实可以用查找asc码确定它是否为英文或中文(好在中文没有asc码^_^)比如
str="abcdefghijklmn"
redim i,j,k
j=0
for i=1 to 118 '如果您想查到英文为止,我记得大Z是118
for j=1 to len(str)
if instr(str,j)=chr(i) then
因为是英文,所以要做您的想做的语句
else
是中文,做您想做的语句
end if
next
next

思路应该是这样,编程就要靠自已!
KUMOZAKI 2003-09-11
  • 打赏
  • 举报
回复
CSDN果然多高手,小弟还需要向各位大哥学习!
retrieve 2003-09-11
  • 打赏
  • 举报
回复
还要判断是中文还是英文阿,如果还有英文+中文 该怎么办?
nchen123 2003-09-11
  • 打赏
  • 举报
回复
cqfeng() ,向你学习!
nchen123 2003-09-11
  • 打赏
  • 举报
回复
<%
str = "是宽度分散积分飞机大负担爱戴积分为了电话打开换行"

dim a(50)

j = 0
for i = 0 to cint(len(str)/3) - 1
'response.write j
a(j) = mid(str,(i*3 + 1),3)
j = j + 1
next

for k = 0 to j - 1
a(k) = a(k) & " "
'response.write "<br>a" & k & " = " & a(k)
next

newstr = trim(join(a))

response.write "newstr=" & newstr


%>
bubuy 2003-09-11
  • 打赏
  • 举报
回复
佩服楼上的,多学习
cqfeng 2003-09-11
  • 打赏
  • 举报
回复
<% str = "是宽度分散积分飞机大负担爱戴积分为了电话打开换行"
j = 3
for i = j to len(str) step 3
str = left(str,j)&" "&right(str,len(str)-j)
j = j + 4
next
response.write str
%>
bubuy 2003-09-11
  • 打赏
  • 举报
回复
<%
function putspace(content,a)
dim str,i,j,lenth
i=0
lenth=len(content)
for j=1 to lenth
if i=a then
str=str & " "
i=0
end if
str=str & mid(content,j,1)
i=i+1
next
putspace=str
end function
'像下面一样用
response.Write(putspace("bubuytzc",3))
%>
johnnywang1980 2003-09-11
  • 打赏
  • 举报
回复
&" "
balloy 2003-09-11
  • 打赏
  • 举报
回复
写个循环不就得了吗?

28,390

社区成员

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

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