Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

escape a single quote (') in INDEX string-function.

Hi,

I need to find out a way to identify INDEX of a single-quote, for example in string: Best Squash Player in '1998' is 'XYZ'. I want to find the index of first single-quote (the one just before 1998).

I tried something like this Index('Best Squash Player in ''1998'' is ''XYZ'','''',1). But it results into an error.

Each of the single-quotes is preceded by another single-quote as an escape character.

Thanks.

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

If your input is in variable, then try like this

=Index(vStr,chr(39),1)


EDIT: Value of vStr is Best Squash Player in '1998' is 'XYZ'

You can use quote without chr(39) when you assign string to a variable

View solution in original post

4 Replies
anbu1984
Master III
Master III

=Index('Best Squash Player in ' & Chr(39) &'1998' & chr(39) & ' is ' & chr(39) & 'XYZ' & chr(39),chr(39),1)

Not applicable
Author

Hi Anbu. Thanks for a quick response. But I was wondering if my string was dynamic or stored in a variable,  the above solution may not hold correct. Because in that case I would not be in a position to identify and place chr(39) dynamically.

Sorry, if I missed that part in my question, but it would be best if you put forward a dynamic approach.

anbu1984
Master III
Master III

If your input is in variable, then try like this

=Index(vStr,chr(39),1)


EDIT: Value of vStr is Best Squash Player in '1998' is 'XYZ'

You can use quote without chr(39) when you assign string to a variable

Not applicable
Author

Awesome. It worked. Thank you!