Results 1 to 5 of 5

Thread: search/find

  1. #1
    Guest
    is there any kind of search/find string function in VB?
    I tried

    if string1 contains("L") then
    etc etc
    but it didnt work....
    lets say I want to find all ":"'s in a string, and remove them.... how would i do that?

  2. #2
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    Use the Replace function.
    The code below will replace all of the colons in the text
    assigned to strTemp with an empty string.

    Code:
    Private Sub Command1_Click()
        Dim strTemp As String
        strTemp = " Line1: " & " Line2: " & " Line3: "
        Debug.Print strTemp   'Check value of strTemp
        strTemp = Replace(strTemp, ":", "")
        Debug.Print strTemp   'See that all :s have been removed
    End Sub
    Hope this helps.
    JC

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Are using VB6?
    Good.

    To search in a string use InStr or InStrRev:
    Code:
    Dim iCharPos As Integer
    iCharPos = InStr(1, "abcdefghijklmnop", "gh", vbTextCompare)
    If "gh" is in the string then it will return the position
    where it found it in the string, if it is not in the string
    then it will return 0. InStrRev is basically the same thing,
    but it starts from the end of the string instead, this function
    is only available in VB6.

    To remove all occurences of a certain string within a
    string then use Replace:
    Code:
    Dim sNewString As String
    sNewString = Replace("Please:remove:all:of:the:colons:.", ":", vbNullString, 1, , vbTextCompare)
    This function is only available in VB6. If you're not using
    VB6 then you'll have to use a loop and combination of InStr
    and Mid to do the replacing.

    Later.
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  4. #4
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Talking

    I guess jcouture100 beat me to it while I was writing
    my response up. You see that face in my code? That's
    weird, I didn't know it was picked up in a code block, cool!
    Code:
    Dim :) :o :p :( ;) As New BugInVBWorld
    [Edited by SonGouki on 05-07-2000 at 01:30 AM]
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  5. #5
    Guest
    thank you.... very much...
    I do have VB6

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