Results 1 to 3 of 3

Thread: Looking for character in a STRING

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    South Africa
    Posts
    69

    Question Looking for character in a STRING

    Hi

    How can I search for a character (i.e. '&' or '+' or '%' or ',') in a string?


    Thanks in advance
    My software doesn't have bugs, It has undocumented features!

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Use the instr function
    [copy-past from MSDN]
    Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

    Syntax

    InStr([start, ]string1, string2[, compare])

    The InStr function syntax has thesearguments:

    Part Description
    start Optional.Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start containsNull, an error occurs. The start argument is required if compare is specified.
    string1 Required.String expression being searched.
    string2 Required. String expression sought.
    compare Optional. Specifies the type ofstring comparison. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison.


    Settings

    The compare argument settings are:

    Constant Value Description
    vbUseCompareOption -1 Performs a comparison using the setting of the Option Compare statement.
    vbBinaryCompare 0 Performs a binary comparison.
    vbTextCompare 1 Performs a textual comparison.
    vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.


    Return Values

    If InStr returns
    string1 is zero-length 0
    string1 is Null Null
    string2 is zero-length start
    string2 is Null Null
    string2 is not found 0
    string2 is found within string1 Position at which match is found
    start > string2 0
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    South Africa
    Posts
    69

    Thumbs up

    Thanks - I'm gonna try the code now.
    My software doesn't have bugs, It has undocumented features!

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