-5

Comparing two strings that are "Random" and "RandoM", would result in a true case. What I want to do is to check also for the lower and upper cases (case-sensitive) and return false in this example. Right now, what I have is

userText = userText + e.target.value;
            if (userText[userText.length-1] != typeracertext[userText.length-1])
            {
                e.target.value = e.target.value.substring(0, e.target.value.length-1);
                return;
            }

and it return true when there is difference in the lower-upper cases. Any ideas?

EDIT: Found a solution, so for anyone that is struggling to find one, here is your solution:

str1.localeCompare(str2) = 
//returns 0 if true
//return -1 if str2 is stronger
//returns 1 if str1 is stronger
RVasilev
  • 7
  • 1
  • 5
  • Does this answer your question? [How to do case insensitive string comparison?](https://stackoverflow.com/questions/2140627/how-to-do-case-insensitive-string-comparison) – Jim G. Sep 16 '22 at 16:48
  • @JimG. Isn't this regardless of upper and lower case? What I need is a case sensitive comparison – RVasilev Sep 16 '22 at 17:02

1 Answers1

0

I don't know if i'm understanding your question, but I hope it could help you:

a = "Random"; b = "RandoM";
a != b ==> true   (what you have now)
a.toLowerCase() != b.toLowerCase() ==> false (i believe that this is what you want).
You could also use .toUpperCase() of course

.

Regards,