Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Test each character of string (Windows 2000 and la

    I have a file name that has been retrieved as a string variable:

    strFileName = Selection()

    I want to test each character of strFileName to determine whether it is the apostrophe (') character Chr(39).

    How can I do this? I was hoping for an alternative to doing a Find on the string.

    Many thanks

    PeteF

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Test each character of string (Windows 2000 and la

    You can use the InStr function:
    <code>
    If InStr(strFileName, "'") > 0 Then
    ...
    End If
    </code>
    InStr will return the first position where the search string is found, or 0. Examples:

    <code>InStr("Woody's Lounge", "'") = 6
    InStr("Woody Leonhard", "'") = 0</code>

    If you really want to test character by character:
    <code>
    Dim i As Integer
    For i = 1 to Len(strFileName)
    If Mid(strFileName, i, 1) = "'" Then
    ...
    End If
    Next i</code>

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test each character of string (Windows 2000 and la

    You could also make use of the Start argument of InStr:<pre>Dim strTest As String
    Dim pos As Long
    strTest = "That's what's tested."
    pos = 1
    pos = InStr(pos, strTest, "'")
    While pos > 0
    Debug.Print pos
    pos = InStr(pos + 1, strTest, "'")
    Wend
    </pre>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  4. #4
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test each character of string (Windows 2000 an

    Thanks Hans

    Your first example was suffiicent - I didn't really need to test character by character - just find an instance and stop at that point:

    Thank you also Klaus for your suggestion which I will note for future reference.

    PeteF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •