More String Methods.
The first one checks if the string is empty, it consider blank spaces as the string is empty
String.prototype.IsEmpty = function () {
var temp = this.toString();
for (var i=0; i < temp.length; i++) {
if (temp.substr(i, 1) !=("" || " ")) {
return false;
}
}
return true;
}
Usage:
myString = new String(" ");
if (myString.IsEmpty()) {
trace("String is empty");
} else {
trace("String not empty");
}
One more, this one clears those annoying newlines when you load text from a .txt
String.prototype.ClearNewLines = function () {
var start = 0
var temp= this.toString();
for (var i=0; i < temp.length/2; i++) {
var pointer = temp.indexOf("\n",start);
var output = output + temp.slice(start, pointer);
start = pointer + 1
if (pointer == -1) {
return output;
}
}
}
The first one checks if the string is empty, it consider blank spaces as the string is empty
String.prototype.IsEmpty = function () {
var temp = this.toString();
for (var i=0; i < temp.length; i++) {
if (temp.substr(i, 1) !=("" || " ")) {
return false;
}
}
return true;
}
Usage:
myString = new String(" ");
if (myString.IsEmpty()) {
trace("String is empty");
} else {
trace("String not empty");
}
One more, this one clears those annoying newlines when you load text from a .txt
String.prototype.ClearNewLines = function () {
var start = 0
var temp= this.toString();
for (var i=0; i < temp.length/2; i++) {
var pointer = temp.indexOf("\n",start);
var output = output + temp.slice(start, pointer);
start = pointer + 1
if (pointer == -1) {
return output;
}
}
}