SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect hyphen at end of string

    Hi guys

    I hope you can help me out with this.

    I need to detect if a string has a hyphen at the end of it.

    ---------------

    Eg:

    Mystring = "the quick brown fox-"

    If a hyphen exists at the end of the string then...

    Do this

    If a hyphen does not exist at the end of the string then...

    Do that

    --------------


    How would I achieve this? Any help would be fully appreciated.

    Best regards

    Rod from the UK

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vbscript has a "right" function to retrieve characters and "strcomp" to determine a match

    http://www.w3schools.com/vbscript/func_right.asp

    http://www.w3schools.com/vbscript/func_strcomp.asp

    retrieve what you want and use the "if" test to determine whether or not it is a hyphen.

    If StrComp(Right(Trim(Mystring) ,1),"-") = 0 then

    Do this

    else

    Do that

    end if

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent - thanks Webber123456

    Best regards

    Rod from the UK


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
  •