Results 1 to 3 of 3

Thread: manipulating a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    68

    manipulating a string

    I have a string like so:
    hey how are you

    I want to change it so its like this:
    hey *how are you

    with the asterisk after the 1st space. I would like to know the best way to do this. Thanks in advance.
    -Maddox

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    68
    Did it myself thanks.
    -Maddox

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    I'd done it so you might as well have it...

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Dim intPos As Integer
    4. Dim str As String
    5. Dim strStore As String
    6.  
    7. str = Text1.Text
    8.  
    9. intPos = InStr(1, str, " ", vbTextCompare)
    10.  
    11. If intPos > 0 Then
    12.     ' store string after space
    13.     strStore = Right$(str, Len(str) - intPos)
    14.     ' place asterisk after first space
    15.     Mid$(str, intPos + 1) = "*"
    16. End If
    17.  
    18. Text2.Text = Left$(str, intPos + 1) & strStore
    19.  
    20. End Sub
    21.  
    22. Private Sub Form_Load()
    23.  
    24. Text1.Text = "Enter a string"
    25. Text2.Text = ""
    26.  
    27. End Sub
    place 2 textboxes and a command button on a form

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