Forum Discussion

mishutkin's avatar
mishutkin
Occasional Contributor
12 years ago

Problem with a single quotation mark in a string

Can't find a description of this problem anywhere...

I have a script written in VBScript. I am trying to see if a string contains a substring that has a single quotation mark in it:



String = "Let's bring it up later"

Substring = "Let's bring"



Res = aqString.Find(String, Substring)



Why I am getting -1, meaning that the string does not contain the substring? If I reduce the substring to "s bring" than I get a positive result. Looks like the apostrophe (single quote) has something to do with it... But why does it? Single quotes are allowed in VBScript strings.

8 Replies

  • mishutkin's avatar
    mishutkin
    Occasional Contributor
    Nope. Same problem: InStr returns 0, meaning that the substring was not found in the string...

    Does a single quote require escaping or something when used as an apostrophe, i.e., it does not have a matching single quote?
  • mishutkin's avatar
    mishutkin
    Occasional Contributor
    The problem is not with string functions. The substring is read from an Excel data file. In there " ' " is used an apostrophe. But when it is placed in a text box on a web page it becomes " ’ " (a single quote)...
  • Hi,



    try adding a escape character(\)  in the string and see if it works.



    regards,

    saurabh
  • sastowe's avatar
    sastowe
    Super Contributor
    How are you identifying the quote as the culprit? I have never heard of a difference between "apostrophe" and single quote in a *string* data type. Something like rtf might have a smart quote. For debugging purposes, can you loop through each character in each string and Char() it? Make sure your strings are the same?
  • sastowe's avatar
    sastowe
    Super Contributor
    My bad. Not char() asc(). Compare the character codes.
  • aqAnt's avatar
    aqAnt
    SmartBear Alumni (Retired)

    Hello Misha,


    Are you using localized versions of Windows and Excel? How do you read data from your file?

  • mishutkin's avatar
    mishutkin
    Occasional Contributor
    Guys, thanks for your replies, but I already identified the problem, as I mentioned in my last post.

    I read the string from an Excel data file and placed it in a text box on a web page. Then I searched for a substring in a string that was a part of an HTML object where I had placed it. The problem is that HTML replaced " ' " with " ’ " when the string was placed in an object on the web page. And these characters are not the same, of course...