Results 1 to 6 of 6

Thread: need help with strings

  1. #1
    Guest
    I have a some text fields which I am using to populate a listview box, but I can't arbirtrarily limit the maxt no of characters for any given entry.

    What I intend to do is have it take any words that would not fit on one line onto the next line.

    I'm kind of at a loss as I have never really had to do any string manipulation in VB before, but as I see it there are two things I need to do. I know beforehand how many lines I will need for a given string, as well as how many characters can fit on each line.

    For example, if I had a 50 character string and could fit 35 characters per line, I would go to character 35 and work backwards until the first space, splitting the string there.

    What I need to know is
    a) is there any kind of a function to split a string into two or more smaller strings?
    b) how do I manipulate a string character by character?

    also if you happen to know the ascii code for a blank space that would be most appreciated.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Ascii Character = 32

    If your string is 55 and you want 30 of it
    myNewString = Left(myOldstring,30)
    MyOtherEnd = Right(myoldstring,25)

    Check out MidString and InStr functions

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    Thanks alot... now that I have that part I just need to know how you can manipulate s string character by character.


  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    The following is a very simple example of going through a string one position at a time.

    Code:
    Private Sub Command1_Click()
        Dim strTest As String
        Dim intLength
        Dim x As Integer
        
        strTest = "This is a test string"
        intLength = Len(strTest)
        
        For x = 1 To intLength
            Debug.Print Mid(strTest, x, 1)
        Next x
    End Sub

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343

    Strings

    Dont know if this is what you want...

    Dim strTest as String

    strTest = "bla bla....."
    If len(strTest) > 35 Then
    strTest = Mid(strTest, 1, inStr(1,strTest, " "))
    End if

    /Smirre

    Visual Basic
    C, C++
    Java
    Access
    SQL Server

    MCP, MCSD

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    slight addition to jbart's code.

    Code:
    Manipulation:
    Private Sub Command1_Click()
        Dim strTest As String
        Dim intLength
        Dim x As Integer
       
        strTest = "This is a test string"
        intLength = Len(strTest)
    'change all i to M    
        For x = 1 To intLength
        If Mid(strTest, x, 1) = "i" Then Mid(strTest, x, 1) = "M"
           Next x
        MsgBox strTest
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width