string manipulation

string manipulation

Anonymous
Not applicable
349 Views
4 Replies
Message 1 of 5

string manipulation

Anonymous
Not applicable
Hello, I have a long text string that i want to divide into 4 nearly equal parts. But i don't want to make the break in the middle of words. Does anyone have a good way to do this? i tried to use "instr" to find the nearest vbcr in the text to make the break at a clean spot but it doesn't work. 'DEVIDE THE SEQUENCE INTO FOUR CHUNKS Dim total As Integer total = Len(Sequence) Dim Y As Integer Y = total / 4 For x = 0 To 2 While InStr(Y, Sequence, vbCrLf, vbTextCompare) = False Y = Y + 1 Wend mT(x) = Left(Sequence, Y) Sequence = Right(Sequence, Len(Sequence) - Y) Y = total / 4 Next x mT(3) = Sequence Any ideas? thanks jm
0 Likes
350 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
while (character position, "john m" wrote in message news:41bf486f$1_2@newsprd01... > Hello, > > I have a long text string that i want to divide into 4 nearly equal > parts. > > But i don't want to make the break in the middle of words. Does anyone have > a good way to do this? > > i tried to use "instr" to find the nearest vbcr in the text to make the > break at a clean spot but it doesn't work. > > 'DEVIDE THE SEQUENCE INTO FOUR CHUNKS > Dim total As Integer > total = Len(Sequence) > Dim Y As Integer > Y = total / 4 > For x = 0 To 2 > While InStr(Y, Sequence, vbCrLf, vbTextCompare) = False > Y = Y + 1 > Wend > mT(x) = Left(Sequence, Y) > Sequence = Right(Sequence, Len(Sequence) - Y) > Y = total / 4 > Next x > mT(3) = Sequence how about identifying the spaces, and use those to break the string? basically something like: while Mid(Sequence,Y)<>" " Y=Y+1 Wend
0 Likes
Message 3 of 5

Anonymous
Not applicable
"john m" wrote in message news:41bf486f$1_2@newsprd01... > Hello, > > I have a long text string that i want to divide into 4 nearly equal > parts. > > But i don't want to make the break in the middle of words. Does anyone have > a good way to do this? > > i tried to use "instr" to find the nearest vbcr in the text to make the > break at a clean spot but it doesn't work. My first thought: Split the string by spaces, divide the total number by 4 and rebuild your 4 separate parts, something like: vList = Split(sOriginalString," ") iCnt = ubound(vList) iLen = iCnt / 4 sOne = substr(sOriginalString,1,iLen) sTwo = substr(sOriginalString,1+iLen,iLen) ...you get the idea
0 Likes
Message 4 of 5

Anonymous
Not applicable
Hi John, Try something along these lines: Note: I have not shown dimensioning of all the variables I've used dim vStr as variant vStr = Split (sLongTextString, " ") iDivideNumber = Len ( sLongTextString) / 4 sStr1 = vStr(0) Do while Len (sStr1) < iDivideNumber i = i + 1 sStr1 = sStr1 & " " & vStr(i) Loop i = i + 1 sStr2 = vStr(i) Do while Len (sStr2) < iDivideNumber i = i + 1 sStr2 = sStr2 & " " & vStr(i) Loop i = i + 1 sStr3 = vStr(i) Do while Len (sStr3) < iDivideNumber i = i + 1 sStr3 = sStr3 & " " & vStr(i) Loop i = i + 1 sStr4 = vStr(i) For j = i + 1 to Ubound(vStr) sStr4 = sStr4 & " " & vStr(j) Next j You could play with the dividing points as you like. As I've done it the last string will be longest. Adjusting iDivideNumber by adding a value like 3 or 4 may create a more uniform set of line lengths. -- Laurie Comerford CADApps www.cadapps.com.au "john m" wrote in message news:41bf486f$1_2@newsprd01... > Hello, > > I have a long text string that i want to divide into 4 nearly equal > parts. > > But i don't want to make the break in the middle of words. Does anyone have > a good way to do this? > > i tried to use "instr" to find the nearest vbcr in the text to make the > break at a clean spot but it doesn't work. > > 'DEVIDE THE SEQUENCE INTO FOUR CHUNKS > Dim total As Integer > total = Len(Sequence) > Dim Y As Integer > Y = total / 4 > For x = 0 To 2 > While InStr(Y, Sequence, vbCrLf, vbTextCompare) = False > Y = Y + 1 > Wend > mT(x) = Left(Sequence, Y) > Sequence = Right(Sequence, Len(Sequence) - Y) > Y = total / 4 > Next x > mT(3) = Sequence > > Any ideas? > > thanks > jm > > >
0 Likes
Message 5 of 5

Anonymous
Not applicable
thanks for all the responses! i just pasted this one in and it worked! thanks "Ron Mills" wrote in message news:41bf4dea$1_3@newsprd01... > while (character position, > "john m" wrote in message > news:41bf486f$1_2@newsprd01... > > Hello, > > > > I have a long text string that i want to divide into 4 nearly equal > > parts. > > > > But i don't want to make the break in the middle of words. Does anyone > have > > a good way to do this? > > > > i tried to use "instr" to find the nearest vbcr in the text to make the > > break at a clean spot but it doesn't work. > > > > 'DEVIDE THE SEQUENCE INTO FOUR CHUNKS > > Dim total As Integer > > total = Len(Sequence) > > Dim Y As Integer > > Y = total / 4 > > For x = 0 To 2 > > While InStr(Y, Sequence, vbCrLf, vbTextCompare) = False > > Y = Y + 1 > > Wend > > mT(x) = Left(Sequence, Y) > > Sequence = Right(Sequence, Len(Sequence) - Y) > > Y = total / 4 > > Next x > > mT(3) = Sequence > > how about identifying the spaces, and use those to break the string? > > basically something like: > > while Mid(Sequence,Y)<>" " > Y=Y+1 > Wend > > >
0 Likes