indexOf

I need to search the position of “v” (including the quotes) in a Text

dim pos as integer pos = textLine.indexOf(chr(34)+"v"+chr(34))

This code does not work chr(34) is not valid it seems.

Do I miss something?

Take a look at the binary value of TextLine() - perhaps the quotes are not 34s e.g. they may be “smart quotes”?

Something like this would do the trick?

pos = textLine.indexOf("""v""")

Odd, this works fine.

@Michael:
The binary value is 34 (checked this). So thats why it is odd it didn’t work. :slight_smile:

that sounds like a bug in string concatenation then, if chr(34) + “v” + chr(34) is not equal to “”“v”""

Remember the replacement for “Chr” in the new framework is “FromUnicodeCodepoint” if necessary:

http://xojo.helpdocsonline.com/text$FromUnicodeCodepoint

I just think that’s overkill when you’re just talking about something like quotes :slight_smile:

Or just use &u22…

So this raises the question, though: using Text datatype, what does

chr(34)+"v"+chr(34)

evaluate to?

[quote=151423:@Michael Diehr]So this raises the question, though: using Text datatype, what does

chr(34)+"v"+chr(34)

evaluate to?[/quote]

This evaluates to a String because Chr returns a String. If you were to write this:

&u22 + "v" + &u22

The type is would be context-dependent as to whether it’s String or Text.

From the original post, I was assuming that his code compiled, but failed at runtime. That would be weird to me since I’d assume that the String would get promoted to Text in a sensible way.

But now after re-reading it, perhaps I’m wrong and it’s just a compile error? That would be quite different.