CASE INSENSITIVE example?

digitalbeat

Member
Licensed User
Longtime User
Hi, I've searched the documentation and the threads but I can't seem to find a good example. I want to do a search for a substring where I want a match to occur regardless of the case. For example.
String = "I am glad today is Friday"
pattern = "friday"
I want to "find" and match the above string even if the word is spelled Friday, FRIDAY, or some other combination of upper and lower case. It would seem that CASE_INSENSITIVE being set would do this but I can't find any examples of using it and it keeps giving me errors when I try to use it.
Thanks
 

Rioven

Active Member
Licensed User
Longtime User
Sample

digitalbeat,

Can be this...

B4X:
Dim Stringx, pattern As String

Stringx = "I am glad today is Friday"
pattern = "friday"

Msgbox(Stringx.ToUpperCase.IndexOf(pattern.ToUpperCase),"location")


Will display 19 (location from Stringx)

(Note: if not found will return -1)


Rioven
 
Last edited:
Upvote 0

digitalbeat

Member
Licensed User
Longtime User
I will give that a try but...

Thanks Rioven,
I will give that example a try (its a lot cleaner than my working code), but I was originally using regex and matcher and saw that you could set the comparisons to be CASE INSENSITIVE I think and I was wondering if anyone had an example of doing that because every time I try to use the method it just gives me an error.
 
Upvote 0

Rioven

Active Member
Licensed User
Longtime User
not simple...

Hi digitalbeat,

I have just started B4A in a week and I haven't looked at regex matcher and seems not simple.
There is a link from B4A Helpviewer HERE
 
Upvote 0

digitalbeat

Member
Licensed User
Longtime User
Hi Erel;
Yes I did read it but it didn't give an example of using CASE INSENSITIVE which is what I was asking about. I use REGEX to match a SINGLE LETTER occurrence in a string i.e (a) or (A) with this expression:
pattern = "^\(([A-Za-z])\)"
m1 = Regex.Matcher(pattern, istr)
and it appears to work.
If I code m1 = Regex.CASE_INSENSITIVE.Matcher(pattern, istr) then it fails to compile so I am missing something that I think a simple example of its usage (which isnt in the tutorial) would explain.
The CASE INSENSITIVE would simplify things if I understood how to make it work. Thanks
 
Upvote 0
Top