Android Question Search a String for characters including single quotes

GuyBooth

Active Member
Licensed User
Longtime User
I'm trying to return the result of searching a string for 's.
I have tried the following - among others - which all return false
B4X:
MyString.contains("'s")
MyString.contains($"${Chr(39)}s"$)
MyString.contains($"'s"$)
What am I missing?
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I don't know how the contains method is implemented, if it's based off a regex you might try escaping the single-quote with a backslash, e.g.
B4X:
MyString.Contains("\'s")
If that still fails, then I'd be willing to bet the character you're comparing against in the string isn't actually Chr(39).
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
I don't know how the contains method is implemented, if it's based off a regex you might try escaping the single-quote with a backslash, e.g.
B4X:
MyString.Contains("\'s")
If that still fails, then I'd be willing to bet the character you're comparing against in the string isn't actually Chr(39).
I actually don't care about "chr(39)". I'm simply trying to find if my string contains the characters 's
And no,
B4X:
MyString.contains("\'s")
sadly doesn't work.
Thanks for the thought though
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tried this and it retirned true:
B4X:
Dim mystring As String = "it's actually useful"
    Log(mystring.contains("'s"))   'returns true
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Thanks for the sanity check Mahares.
Seems I had previously chopped an extra letter off the end of the word :mad:
All fixed.
 
Upvote 0
Top