str="abcddfa efgh ijkmnopq trewer" sel_space: for i =1 to len(str) if left(str,i)=" " then if len(str1)+i<=15 then str1=left(str,i) num=len(str)-i str=mid(str,i+1,num-1) else str2=left(str,i) num=len(str)-i str=mid(str,i+1,num-1) endif goto space end if next i 其余部分你自己写吧
Private Function Split_StringByLength(SplitString As String, length As Integer, VarArray() As String, Errstring As String) As Boolean Dim i As Integer Dim j As Integer Dim Temparray() As String On Error GoTo ErrFlag Split_StringByLength = False If Trim(SplitString) = "" Then Exit Function Temparray = Split(Trim(SplitString), Chr(13) + Chr(10)) For i = 0 To UBound(Temparray) If Len(Temparray(i)) <= length Then ReDim Preserve VarArray(i) VarArray(i) = Temparray(i) Else For j = 0 To Len(Temparray(i)) / length ReDim Preserve VarArray(i + j + 1) VarArray(i + j + 1) = Mid(SplitString, IIf(i = 0, 1, i * length), length) Next j End If Next i Split_StringByLength = True Exit Function
对不起,少了这三句 ErrFlag: Errstring = Err.Description End Function
private const Len_Limit as long=15 dim arrClause() as string arrClause=split(sInput,space$(1)) dim sView as string dim i as long for i=0 to ubound(arrClause) sView=sView & arrClause(i) if len(sView)>=Len_Limit then debug.print sView sView=vbNullString end if next
sel_space:
for i =1 to len(str)
if left(str,i)=" " then
if len(str1)+i<=15 then
str1=left(str,i)
num=len(str)-i
str=mid(str,i+1,num-1)
else
str2=left(str,i)
num=len(str)-i
str=mid(str,i+1,num-1)
endif
goto space
end if
next i
其余部分你自己写吧
Dim i As Integer
Dim j As Integer
Dim Temparray() As String
On Error GoTo ErrFlag
Split_StringByLength = False
If Trim(SplitString) = "" Then Exit Function
Temparray = Split(Trim(SplitString), Chr(13) + Chr(10))
For i = 0 To UBound(Temparray)
If Len(Temparray(i)) <= length Then
ReDim Preserve VarArray(i)
VarArray(i) = Temparray(i)
Else
For j = 0 To Len(Temparray(i)) / length
ReDim Preserve VarArray(i + j + 1)
VarArray(i + j + 1) = Mid(SplitString, IIf(i = 0, 1, i * length), length)
Next j
End If
Next i
Split_StringByLength = True
Exit Function
ErrFlag:
Errstring = Err.Description
End Function
dim arrClause() as string
arrClause=split(sInput,space$(1)) dim sView as string
dim i as long
for i=0 to ubound(arrClause)
sView=sView & arrClause(i)
if len(sView)>=Len_Limit then
debug.print sView
sView=vbNullString
end if
next