比如一个字符串ddddddddddddddddddddddddddddd飞腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏
首先我要截取200个字节(如果都是字母就是200个 都是汉字 100个)我不清楚到底VB里英文和汉字是不是都占两个字节但是美观上 两个英文字母 和一个汉字的宽度是一样的 所以 以汉字为标准然后 25个字换一行 (如果都是英文字母那应该有50个字母)这个该如何实现
首先我要截取200个字节(如果都是字母就是200个 都是汉字 100个)我不清楚到底VB里英文和汉字是不是都占两个字节但是美观上 两个英文字母 和一个汉字的宽度是一样的 所以 以汉字为标准然后 25个字换一行 (如果都是英文字母那应该有50个字母)这个该如何实现
用len函数来得到的长度汉字为1,英文为1
Dim Str As String, S As String, i As Integer
Text1.Text = ""
Str = "ddddddddddddddddddddddddddddd飞腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏"
'Str = "abcdeftghijlzdfgzsdcvzbczvbnxfnbnvbnvbnmcbmcbmcbmcbmcghnmcgjxgfnjcbncvbnvbncvbncbncvbnmcvbmnbmcvbmbvmcbmgfxfgfgsdfgzsdfgsdfgdfhfbnzdfhzdfhzdfhzfvnzxfnhfnhzsfnzdfnbzdfnzfzdfbnzdfbnzsdfnznznzfgnfgnV"
For i = 0 To (LenB(Str) \ 50)
S = MidB(Str, i * 50 + 1, 50)
Text1.Text = Text1.Text & S & vbCrLf
Next
End Sub
Dim strText$, strOut$, strChr$
Dim iBegin%, iEnd%, iLen%, iCount%
strText = "ddddddddddddddddddddddddddddd飞腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞ggggggg腾浏"
strOut = ""
iCount = 0: iLen = 0: iBegin = iEnd
For iEnd = 1 To Len(strText)
strChr = Mid$(strText, iEnd, 1)
If (Asc(strChr) > 0) Then
iLen = iLen + 1
iCount = iCount + 1
Else
iLen = iLen + 2
iCount = iCount + 2
End If
If (iLen > 200) Then Exit For
If (iCount >= 50) Then
If (iCount = 50) Then
strOut = strOut & strChr & vbCrLf
iCount = 0
Else
strOut = strOut & vbCrLf & strChr
iCount = 2
iLen = iLen + 1
End If
Else
strOut = strOut & strChr
End If
Next
Debug.Print strOut
End Sub
Option ExplicitPrivate Sub Command1_Click()
Dim s As String
Dim i As Long
Dim k As Long
Dim tmp As String
s = "ddddddddddddddddddddddddddddd飞腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏,ddddddddddddddddddddddddddddd飞腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助--方圆软件,飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏览器腾浏览器(FlyIe)在线帮助-飞腾浏飞腾浏"
k = 25
For i = 1 To 8
tmp = SubString(s, k)
s = Replace(s, tmp, "", , 1)
Debug.Print tmp '& vbCrLf
Next
End SubPrivate Function SubString(ByVal Source As String, ByVal length As Long) As String
Dim L As Long
Dim i As Long
L = Len(Source)
i = 0
While i < L And i < length
i = i + 1
If Asc(Mid(Source, i, 1)) < 0 Then length = length - 1
Wend
If length < i Then length = i
If length > L Then length = L
SubString = Mid(Source, 1, length)
End Function