Help with toUpperCase or toLowerCase
Hi Everybody. I'm having some difficulties with the following.
I need to turn a value in a search bar and a value from a database to UpperCase or LowerCase. I'm doing the following:
var data_1 = search_bar.value;
var data_2 = myResultSet.fieldByName('name');
data_1.toUpperCase()
data_2.toUpperCase()
if (data_1 == data_2){ —> do something.
Titanium is giving me an error, saying that data_2 is not a string. How can I accomplish this?
I just want to turn both values into lower Case or UpperCase, so if the user types in any way, it can search the database and locate the result, no matter how is written.
Hope to hear from you guys. Thanks in advanced!!!
5 Answers
-
Alright!!! I just solved it! I just needed to do this:
data_1 = data_1.toUpperCase(); etc…
Thanks Hal H for you help!
-
Hi Pablo, are you able to output the contents of both data_2 and myResultSet.fieldByName('name') using Ti.API.info()? Do they appear equal? Also try using typeof() to tell you their type. If I have understood you correctly, there is no need to use separate methods based on whether the user has typed their name in upper or lower case - simply choose one and always use that method for each.
-
Hi Hal H. Thanks for answering. Using Ti.API.info() returns data_1 and data_2 as the same as they were written. Meaning that the toUpperCase or toLowerCase is not working. Using typeof() returns that both variables are strings.
I didn't understand the last sentence you wrote. Basically what I need is to both variable be UpperCase or LowerCase in order to both be exactly the same and compare if each other are equal (for example, the user types "flower", but in the database is written "Flower"; if both are in lowercase or uppercase, they will match).
I don't know if this is the best way to achieve this or is there any other way to acomplish this?
Thanks for helping me!
-
Hi Hal H. Thanks for answering. Using Ti.API.info() returns data_1 and data_2 as the same as they were written. Meaning that the toUpperCase or toLowerCase is not working. Using typeof() returns that both variables are strings.
I didn't understand the last sentence you wrote. Basically what I need is to both variable be UpperCase or LowerCase in order to both be exactly the same and compare if each other are equal (for example, the user types "flower", but in the database is written "Flower"; if both are in lowercase or uppercase, they will match).
I don't know if this is the best way to achieve this or is there any other way to acomplish this?
Thanks for helping me!
-
Alright!!! I just solved it! I just needed to do this:
data_1 = data_1.toUpperCase(); etc…
Thanks Hal H for you help!