string manipulation

Discussion in 'AutoCAD' started by john m, Dec 14, 2004.

  1. john m

    john m Guest

    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
     
    john m, Dec 14, 2004
    #1
  2. john m

    Ron Mills Guest

    while (character position,
    how about identifying the spaces, and use those to break the string?

    basically something like:

    while Mid(Sequence,Y)<>" "
    Y=Y+1
    Wend
     
    Ron Mills, Dec 14, 2004
    #2
  3. john m

    TomD Guest

    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
     
    TomD, Dec 14, 2004
    #3
  4. 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
     
    Laurie Comerford, Dec 14, 2004
    #4
  5. john m

    john m Guest

    thanks for all the responses!
    i just pasted this one in and it worked! thanks
     
    john m, Dec 14, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.