Results 1 to 6 of 6

Thread: Search a String

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Search a String

    Ok lets say I have a string composed of this text (including the quotes)

    Hello "bob how are" you?

    what would be the fastest way to search that string to see if it contains a " (quote marks)? I know i could use the mid instruction and put it in the middle of a loop and just check every char one at a time, but that is slow. I cant split the string because i want to keep the " not use it as the dilimiter. Does vb.net have a search function like c++? Because i have a feeling vb would have a built in function that is faster then anything i can write.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could use InStr to check if the " is there.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The String object has an IndexOf method that returns the index of the first instance of the search string or -1 if non is found.
    VB Code:
    1. Dim test As String="Hello ""bob how are"" you?"
    2. If test.IndexOf(ControlChars.Quote)=-1 Then Msgbox("Not Found")

    I'm getting slow in my old age...
    Last edited by Edneeis; Jul 23rd, 2003 at 02:14 AM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313
    so i am guessing that is like the strcmp function in c++? It just returns a boolean true if it is there, or false if it is not there?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313
    I think that may of solved my problem, now to attempt to write some fast code, thank you for your time and help.

  6. #6
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    the indexOf-function doesn't return True or False like your c++Function does. This fucntion returns the index of the string you're looking for int the base-string. When it returns -1, this means that the string is not found.
    I wouldn'd adise to still use the instr-function. This is a VB6-function that is still suported, but it's better to use the .NET-function .IndexOf.
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

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