+ Reply to Thread
Results 1 to 5 of 5

Detecting the space character

  1. #1
    JN
    Guest

    Detecting the space character

    Hi All,

    I am trying to detect the space character in a string but my code is not
    working.

    Thanks for your help.
    JN

    sub demo()

    Dim strlength As Integer
    Dim str As String

    str = "good morning"

    strlength = Len(Trim(str))

    For i = 1 To strlength
    If Mid(str, i, strlength) = Chr(32) Then
    MsgBox "space"
    End If
    Next i

    End Sub



  2. #2
    Dave Peterson
    Guest

    Re: Detecting the space character

    If Mid(str, i, strlength)
    should be
    If Mid(str, i, 1)

    Start in position i for 1 character.

    JN wrote:
    >
    > Hi All,
    >
    > I am trying to detect the space character in a string but my code is not
    > working.
    >
    > Thanks for your help.
    > JN
    >
    > sub demo()
    >
    > Dim strlength As Integer
    > Dim str As String
    >
    > str = "good morning"
    >
    > strlength = Len(Trim(str))
    >
    > For i = 1 To strlength
    > If Mid(str, i, strlength) = Chr(32) Then
    > MsgBox "space"
    > End If
    > Next i
    >
    > End Sub


    --

    Dave Peterson

  3. #3
    JE McGimpsey
    Guest

    Re: Detecting the space character

    One way:

    Const str As String = "good morning"
    Dim nPos As Long
    nPos = InStr(str, " ")
    If nPos Then Msgbox "space at character " & nPos

    In article <[email protected]>,
    "JN" <[email protected]> wrote:

    > Hi All,
    >
    > I am trying to detect the space character in a string but my code is not
    > working.
    >
    > Thanks for your help.
    > JN
    >
    > sub demo()
    >
    > Dim strlength As Integer
    > Dim str As String
    >
    > str = "good morning"
    >
    > strlength = Len(Trim(str))
    >
    > For i = 1 To strlength
    > If Mid(str, i, strlength) = Chr(32) Then
    > MsgBox "space"
    > End If
    > Next i
    >
    > End Sub


  4. #4
    JN
    Guest

    Re: Detecting the space character

    Thanks for your replies...it is now working.

    "JN" <[email protected]> wrote in message
    news:[email protected]...
    > Hi All,
    >
    > I am trying to detect the space character in a string but my code is not
    > working.
    >
    > Thanks for your help.
    > JN
    >
    > sub demo()
    >
    > Dim strlength As Integer
    > Dim str As String
    >
    > str = "good morning"
    >
    > strlength = Len(Trim(str))
    >
    > For i = 1 To strlength
    > If Mid(str, i, strlength) = Chr(32) Then
    > MsgBox "space"
    > End If
    > Next i
    >
    > End Sub
    >




  5. #5
    Tim Williams
    Guest

    Re: Detecting the space character

    Why not use Instr() ?

    In any case, maybe you could try
    ....
    If Mid(str, i, 1) = Chr(32) Then
    ....

    Tim

    --
    Tim Williams
    Palo Alto, CA


    "JN" <[email protected]> wrote in message
    news:[email protected]...
    > Hi All,
    >
    > I am trying to detect the space character in a string but my code is not
    > working.
    >
    > Thanks for your help.
    > JN
    >
    > sub demo()
    >
    > Dim strlength As Integer
    > Dim str As String
    >
    > str = "good morning"
    >
    > strlength = Len(Trim(str))
    >
    > For i = 1 To strlength
    > If Mid(str, i, strlength) = Chr(32) Then
    > MsgBox "space"
    > End If
    > Next i
    >
    > End Sub
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1