| Author |
Message |
john m
Guest
|
Posted:
Wed Dec 15, 2004 1:11 am Post subject:
string manipulation |
|
|
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
|
|
| Back to top |
|
 |
Ron Mills
Guest
|
Posted:
Wed Dec 15, 2004 1:32 am Post subject:
Re: string manipulation |
|
|
while (character position,
"john m" <jmNOSPAM@haengineers.com> wrote in message
news:41bf486f$1_2@newsprd01...
| Quote: | 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 |
|
| Back to top |
|
 |
TomD
Guest
|
Posted:
Wed Dec 15, 2004 1:35 am Post subject:
Re: string manipulation |
|
|
"john m" <jmNOSPAM@haengineers.com> wrote in message
news:41bf486f$1_2@newsprd01...
| Quote: | 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
|
|
| Back to top |
|
 |
Laurie Comerford
Guest
|
Posted:
Wed Dec 15, 2004 1:48 am Post subject:
Re: string manipulation |
|
|
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" <jmNOSPAM@haengineers.com> wrote in message
news:41bf486f$1_2@newsprd01...
| Quote: | 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
|
|
|
| Back to top |
|
 |
john m
Guest
|
Posted:
Wed Dec 15, 2004 2:14 am Post subject:
Re: string manipulation |
|
|
thanks for all the responses!
i just pasted this one in and it worked! thanks
"Ron Mills" <ron.mills@gmail.com> wrote in message
news:41bf4dea$1_3@newsprd01...
| Quote: | while (character position,
"john m" <jmNOSPAM@haengineers.com> 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
|
|
|
| Back to top |
|
 |
|
|
|
|