String
Below are two handy functions to manipulate strings.
//Trim a string:
trim = function(txt_str) {
while (txt_str.charAt(0) == " ") {
txt_str = txt_str.substring(1, txt_str.length);
}
while (txt_str.charAt(txt_str.length-1) == " ") {
txt_str = txt_str.substring(0, txt_str.length-1);
}
// trace(txt_str);
return txt_str;
};
//Trim new line characters:
trimNewline = function(text_str) {
var temp_array = text_str.split(chr(13)+chr(10));
var temp1_array = [];
for (i=0; i < temp_array.length; i++) {
if (trim(temp_array[i]) != "") {
temp1_array.push(trim(temp_array[i]));
}
}
var new_str = temp1_array.join(" ");
return new_str;
};
//Trim a string:
trim = function(txt_str) {
while (txt_str.charAt(0) == " ") {
txt_str = txt_str.substring(1, txt_str.length);
}
while (txt_str.charAt(txt_str.length-1) == " ") {
txt_str = txt_str.substring(0, txt_str.length-1);
}
// trace(txt_str);
return txt_str;
};
//Trim new line characters:
trimNewline = function(text_str) {
var temp_array = text_str.split(chr(13)+chr(10));
var temp1_array = [];
for (i=0; i < temp_array.length; i++) {
if (trim(temp_array[i]) != "") {
temp1_array.push(trim(temp_array[i]));
}
}
var new_str = temp1_array.join(" ");
return new_str;
};

2 Comments:
This post has been removed by a blog administrator.
Earn between $14.37 & $48.99 per resume writing sold, depending on the type of resume & your affiliate level. Resume Writing is our best-selling service. Click Here for more information.
Post a Comment
<< Home