S
Sandy Lewanscheck
Hey everybody!
I have a problem stripping a variable number of <br> and \n
in the beginning of a string. The stripping should only be done
BEFORE and real text comes. So
"<br><br>\n Hello <br> this is a <br> string."
should become
" Hello <br> this is a <br> string."
I've been working on this all day now and for the blink of
an eye it seemed to work, but it doesnt anymore. Any ideas what
is going on and why it won't work?
Thanx in advance, Sandy
this is the function:
function remove_leading_junk(text,what_to_remove)
{
var pos = text.indexOf(what_to_remove);
if(pos!=-1)
{
var bis = text.length;
var length_what = what_to_remove.length;
/// get everything before the <br>
var anfang = text.substr(0,pos);
var start = pos + length_what;
/// get the stuff after the <br>
var rest = text.substr(start, bis);
var expression = /[a-zA-Z0-9_]/;
/// only cut away the stuff before the
/// <br> if there is no text and
/// stuff included
if(expression.test(anfang)==false)
{
return rest;
}
else
{
return 0;
}
}
}
var innerValue = "<br><br>\nHello.";
var what = "<br>";
var result = remove_leading_junk(innerValue,what);
greetz, Sandy
I have a problem stripping a variable number of <br> and \n
in the beginning of a string. The stripping should only be done
BEFORE and real text comes. So
"<br><br>\n Hello <br> this is a <br> string."
should become
" Hello <br> this is a <br> string."
I've been working on this all day now and for the blink of
an eye it seemed to work, but it doesnt anymore. Any ideas what
is going on and why it won't work?
Thanx in advance, Sandy
this is the function:
function remove_leading_junk(text,what_to_remove)
{
var pos = text.indexOf(what_to_remove);
if(pos!=-1)
{
var bis = text.length;
var length_what = what_to_remove.length;
/// get everything before the <br>
var anfang = text.substr(0,pos);
var start = pos + length_what;
/// get the stuff after the <br>
var rest = text.substr(start, bis);
var expression = /[a-zA-Z0-9_]/;
/// only cut away the stuff before the
/// <br> if there is no text and
/// stuff included
if(expression.test(anfang)==false)
{
return rest;
}
else
{
return 0;
}
}
}
var innerValue = "<br><br>\nHello.";
var what = "<br>";
var result = remove_leading_junk(innerValue,what);
greetz, Sandy