0的ASCII码值为48,9的ASCII值为57 根据这个来判断 dim n_first as integer dim n_last as integer dim n as long n_first=0 for n=0 to len(字符串) if n_first=0 and asc(mid(字符串,n+1,1))<48 or asc(mid(字符串,n+1,1))>57 then n_first=n elseif n_first=0 and asc(mid(字符串,n+1,1))<48 or asc(mid(字符串,n+1,1))>57 then n_last=n exit for end if next n 得到两个英文字母的位置重新组合字符串其余的原理一样
利用Split函数,可以快速切分和拼接。Dim yourStr As String Dim Strs() As String Dim i As Integer Dim temp As StringyourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651" Strs = Split(yourStr, " ") temp = Strs(0) For i = 1 To UBound(Strs) - 1 If Left(Strs(i), 1) > "9" Then List1.AddItem temp temp = Strs(i) Else temp = temp & " " & Strs(i) End If Next i List1.AddItem temp
上面的例子是用list控件显示结果。 你可以改成写文本文件。
of123() 对的 竟把Split函数给丢到脑后了 :(!
恩,用split也可以实现,比较简单我的太麻烦了,呵呵
用下面的方法试试: 先用split将字符串分开,再查找首位是字母的元素,然后重新联接 Dim yourStr As String Dim Strs() As String Dim i As Integer Dim temp As String Dim tmp() As Integer,j as Integer Dim Result() as String,k as Integer yourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651" Strs = Split(yourStr, " ") j=0 ReDim Preserve tmp(j) as Integer tmp(0)=0'开始位置 for i=0 to ubound(Strs) if asc(left$(Strs(i),1))>asc("9") then j=j+1 ReDim Preserve tmp(j) as Integer '保留原有数据 if i>0 then tmp(j)=i-1'记录位置,但不记录第一个位置 end if next Redim Result(j) as string '重新组合 for k=0 to ubound(tmp)-1 for i=tmp(k) to tmp(k+1) Result(k)=Result(k) & Strs(i) & " " next print #1,Result(k) next for i=tmp(k) to ubound(Strs) Result(k)=Result(k) & Strs(i) & " " next print #1,Result(k)
刚才写错了一点,正确的如下 Dim yourStr As String Dim Strs() As String Dim i As Integer Dim temp As String Dim tmp() As Integer,j as Integer Dim Result() as String,k as Integer yourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651" Strs = Split(yourStr, " ") j=0 ReDim Preserve tmp(j) as Integer tmp(0)=0'开始位置 for i=1 to ubound(Strs) if asc(left$(Strs(i),1))>asc("9") then j=j+1 ReDim Preserve tmp(j) as Integer '保留原有数据 if i>0 then tmp(j)=i'记录位置,但不记录第一个位置 end if next Redim Result(j) as string '重新组合 for k=0 to ubound(tmp)-1 for i=tmp(k) to tmp(k+1)-1 Result(k)=Result(k) & Strs(i) & " " next print #1,Result(k) next for i=tmp(k) to ubound(Strs) Result(k)=Result(k) & Strs(i) & " " next print #1,Result(k)
For i=0 to ubound(a)-1 step 4
Write #1,a(i) &" "&a(i+1) & " " & a(i+2) & " " & a(i+3) &" " & a(i+4)
next
close #1
用ascii码值判断一下
dim n_first as integer
dim n_last as integer
dim n as long
n_first=0
for n=0 to len(字符串)
if n_first=0 and asc(mid(字符串,n+1,1))<48 or asc(mid(字符串,n+1,1))>57 then
n_first=n
elseif n_first=0 and asc(mid(字符串,n+1,1))<48 or asc(mid(字符串,n+1,1))>57 then
n_last=n
exit for
end if
next n
得到两个英文字母的位置重新组合字符串其余的原理一样
还要再仔细考虑一下
不过思路应该就是这样,要麻烦一点
Dim Strs() As String
Dim i As Integer
Dim temp As StringyourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651"
Strs = Split(yourStr, " ")
temp = Strs(0)
For i = 1 To UBound(Strs) - 1
If Left(Strs(i), 1) > "9" Then
List1.AddItem temp
temp = Strs(i)
Else
temp = temp & " " & Strs(i)
End If
Next i
List1.AddItem temp
你可以改成写文本文件。
竟把Split函数给丢到脑后了
:(!
先用split将字符串分开,再查找首位是字母的元素,然后重新联接
Dim yourStr As String
Dim Strs() As String
Dim i As Integer
Dim temp As String
Dim tmp() As Integer,j as Integer
Dim Result() as String,k as Integer
yourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651"
Strs = Split(yourStr, " ")
j=0
ReDim Preserve tmp(j) as Integer
tmp(0)=0'开始位置
for i=0 to ubound(Strs)
if asc(left$(Strs(i),1))>asc("9") then
j=j+1
ReDim Preserve tmp(j) as Integer '保留原有数据
if i>0 then tmp(j)=i-1'记录位置,但不记录第一个位置
end if
next
Redim Result(j) as string
'重新组合
for k=0 to ubound(tmp)-1
for i=tmp(k) to tmp(k+1)
Result(k)=Result(k) & Strs(i) & " "
next
print #1,Result(k)
next
for i=tmp(k) to ubound(Strs)
Result(k)=Result(k) & Strs(i) & " "
next
print #1,Result(k)
Dim yourStr As String
Dim Strs() As String
Dim i As Integer
Dim temp As String
Dim tmp() As Integer,j as Integer
Dim Result() as String,k as Integer
yourStr = "as1234 23456 21080 00007 23456 cy2345 54321 21080 55155 12345 34213 gyg2349 23212 21080 55155 34527 77651"
Strs = Split(yourStr, " ")
j=0
ReDim Preserve tmp(j) as Integer
tmp(0)=0'开始位置
for i=1 to ubound(Strs)
if asc(left$(Strs(i),1))>asc("9") then
j=j+1
ReDim Preserve tmp(j) as Integer '保留原有数据
if i>0 then tmp(j)=i'记录位置,但不记录第一个位置
end if
next
Redim Result(j) as string
'重新组合
for k=0 to ubound(tmp)-1
for i=tmp(k) to tmp(k+1)-1
Result(k)=Result(k) & Strs(i) & " "
next
print #1,Result(k)
next
for i=tmp(k) to ubound(Strs)
Result(k)=Result(k) & Strs(i) & " "
next
print #1,Result(k)