Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

toUpperCase() not working properly

Hi,

I'm working on a list where I want to be able to search in.
Though I've stumbled on a toUpperCase() problem.

When a line of text contains one or more quotes it doesn't change the case anymore.

var titles = [];
titles[ titles.length ] = "When I was little, this would work";
titles[ titles.length ] = "But now I'm confused.";
titles[ titles.length ] = "It won't even say ‘sorry’";

for( var index = 0; index < titles.length; index++ ) {
  titles[ index ] = titles[ index ].toUpperCase();
}

This will uppercase the first line, but the 2nd and 3rd will remain as they are.

I haven't come across this problem before, so I'm guessing it's a Titanium conversion problem of some sort.

Can anybody verfiy it's not just my problem?

(Edit: changed typo)

— asked August 4th 2010 by Jip Moors
0 Comments

1 Answer

  • It looks a little weird to me the way you are populating the array :)
    Try this maybe:

    titles = [
    "When I was little, this would work",
    "But now I'm confused.",
    "It won't even say ‘sorry’"
    ]
    

    or if you are doing this in a dynamic way use push

    titles=[];
    titles.push("When I was little, this would work");
    titles.push("But now I'm confused.");
    titles.push("It won't even say ‘sorry’");
    

    now the for loop should work fine.

    — answered August 4th 2010 by Dan Tamas
    permalink
    1 Comment
    • the array filling is a legit way and nothing is going wrong there.
      The toUpperCase() is faulty in Titanium Mobile, I have created a work-around which isn't too neat but works for the purpose I'm using it, testing for Alphanumeric search parameters in a string;

      function UpperCased(text) {
       text = text.toUpperCase();
      
       var out = '';
       for(var index = 0; index < text.length; index++) {
        var letter = text.substr(index, 1);
        if(text.charCodeAt(index) > 96) {
         letter = String.fromCharCode(text.charCodeAt(index) - 32);
        }
      
        out += letter;
       }
      
       return out;
      }
      

      Which converts the string to uppercase but if you print the string some extra chars are added, but for comparison on two strings both parsed through the function it all works fine.

      — commented August 4th 2010 by Jip Moors
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.