Wordpress Themes - Debt Consolidation - Moroccan Property - Debt Consolidation - Credit Card

PDA

View Full Version : What the hell isn't going on?


Chri5ty
Feb 11th 2007, 8:31 am
:confused: :eek: Who can tell me what's wrong???
function eliminateSuperfillousSpaces(text){
var b=0;var result=' ';for(var a=0;a<text.lenght;a++){
if(text[a]!=' ' && text[a+1]!=' '){result[b]=text[a];b++;}
if(text[a]!=' ' && text[a+1]==' '){result=text[a];b++;result=' ';b++;}}[B]return result}
This was suposed to eliminate spaces at the beginind and at the end of a string.If there are two spaces they should be eliminated. But why the string "result" remains unchanged?:(

MattD
Feb 11th 2007, 10:57 am
Why not just use something like this?


str = str.replace(/^\s*|\s*$/g,"");


Not had a long look at your code but what I think you doing is are setting result to a single character each time, and not appending the string.

Chri5ty
Feb 11th 2007, 11:43 am
Thanks. But what is that shit?
str = str.replace(/^\s*|\s*$/g,"");
What shoud I do? Be more clearly.

MattEvers
Feb 11th 2007, 11:53 am
Thanks. But what is that shit?

What shoud I do? Be more clearly.

You are not very nice to be asking for help.

http://www.w3schools.com/jsref/jsref_replace.asp

Chri5ty
Feb 11th 2007, 12:23 pm
:mad: I'm getting crazy. I tryed everything.

function StringBuilder(value){this.strings=new Array();this.append(value);}
StringBuilder.prototype.append = function(value){if(value)this.strings.push(value)}
StringBuilder.prototype.clear = function(){this.strings.lenght=1}
StringBuilder.prototype.toString= function(){return this.strings.join("");}

function removeSpaces(text){alert(text);
var result=new StringBuilder();
for(var a=0; a<text.lenght; a++){
if(text[a]!=' '&&text[a+1]!=' ')result.append(text[a]);
if(text[a]!=' '&&text[a+1]==' ')result.append(text[a]+" ");}
alert(result.toString())}
Everytime I get an empty string as a result.:mad: :mad: :mad:

MattD
Feb 11th 2007, 1:10 pm
"That shit" is a regular expression that removes all excess spaces at the start and end of the str variable.