Touppercase

From FacileWiki

ff_toUpperCase(string)

Description

The ability to convert a string entirely to Upper Case letters has obvious importance. For one - it would enable, say, a comparison algorithm to ignore the case of user input. This is most likely the reasoning behind why it would be supported by default in the JavaScript language (according to w3schools.com anyway). That being said, for some reason, this function wasn't able to be used from within facile forms, to the best of the author's knowledge, and no forum messages or anything else addressed this issue at all. So, with no where left to turn, the author decided to write a toUpperCase function and share it with the world. Hopefully it will help others in a similar situation.

Parameters

A string to be converted to upper case

Returns

The string converted to upper case

Code

function ff_toUpperCase(oldword)
{
  newword = '';
  alpha_lower = "abcdefghijklmnopqrstuvwxyz";
  alpha_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (i in oldword){
    for (j in alpha_lower){
      if (oldword[i]==alpha_lower[j]){
        newword += alpha_upper[j];
        break;
      } // if
    } // for j
    if (newword[i] != alpha_upper[j]) newword += oldword[i];
  } // for i
  return newword;
} // ff_toUpperCase

Note

A function to convert strings to lower case, like an ff_toLowerCase would be almost identical to the code above, only with all mentions of alpha_lower and alpha_upper reversed.

| Terms of Use | Privacy | Sitemap |
Editing tools
Personal tools