New methods for the String object.
Today I'm going to start including some of the functions I have created for my daily work and I think they will help you.
The first one outputs the string in reverse order without modifing the original.
String.prototype.Reverse = function(){
var temp;
for (var z=this.length-1;z>-1;--z) {
temp+=this.charAt(z);
}
return temp;
}
Usage:
myString = new String("example");
reverseString = myString.Reverse();
trace (reverseString); => "elpmaxe"
This one checks if the string has Spanish characters like ñ, á, ú, etc..
We have to include two arrays containing the letters:
var lowercase = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n",
"ñ","o","p","q","r","s","t","u","v","w","x","y","z","á","é","í","ó","ú"];
var uppercase= ["A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"Ñ","O","P","Q","R","S","T","U","V","W","X","Y","Z","Á","É","Í","Ó","Ú"];
String.prototype.SpanishLetter = function(){
var letter = this.toString();
for (var i = 0; i < lowercase.length; i++) {
if (letter == lowercase[i] || letter == uppercase[i]) {
return true;
}
}
return false;
}
Usage:
myString = new String("ñ");
if (myString.SpanishLetter()) {
trace("Spanish letter");
} else {
trace("Not Spanish letter");
}
Well I think that's all for today, tomorrow more...
Today I'm going to start including some of the functions I have created for my daily work and I think they will help you.
The first one outputs the string in reverse order without modifing the original.
String.prototype.Reverse = function(){
var temp;
for (var z=this.length-1;z>-1;--z) {
temp+=this.charAt(z);
}
return temp;
}
Usage:
myString = new String("example");
reverseString = myString.Reverse();
trace (reverseString); => "elpmaxe"
This one checks if the string has Spanish characters like ñ, á, ú, etc..
We have to include two arrays containing the letters:
var lowercase = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n",
"ñ","o","p","q","r","s","t","u","v","w","x","y","z","á","é","í","ó","ú"];
var uppercase= ["A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"Ñ","O","P","Q","R","S","T","U","V","W","X","Y","Z","Á","É","Í","Ó","Ú"];
String.prototype.SpanishLetter = function(){
var letter = this.toString();
for (var i = 0; i < lowercase.length; i++) {
if (letter == lowercase[i] || letter == uppercase[i]) {
return true;
}
}
return false;
}
Usage:
myString = new String("ñ");
if (myString.SpanishLetter()) {
trace("Spanish letter");
} else {
trace("Not Spanish letter");
}
Well I think that's all for today, tomorrow more...