CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Posts
    7

    how to search a string character by character

    Hi everyone,

    Need to be able to search a string and compare each character to a list of valid characters.

    example:
    string1="vb-programming"
    string2="vb=programming"
    valid characters are a-z, A-Z, 0-9, _, -, .

    this would find all these characters valid in string1 to be valid and find "=" in string2 to be invalid thus making that string an invalid string

    any help or direction would be appreciated

    btw i have been trying to use instr functions to accomplish this and have only been able to search
    for "1" character at a time

    thx harold



  2. #2
    Join Date
    Aug 1999
    Posts
    7

    Re: how to search a string character by character

    sorry but the category should not be activex, should be controls or misc


  3. #3

    Re: how to search a string character by character


    public Function ValidString(byval sInput as string) as Boolean

    Dim iLen as Integer
    Dim iCtr as Integer
    Dim sChar as string

    iLen = len(sInput)
    for iCtr = 1 to iLen
    sChar = mid(sInput, iCtr, 1)
    If Not sChar Like "[0-9A-Za-z_]" And sChar <> "-" then Exit Function
    next
    ValidString = true

    End Function





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

Featured