strip <br> and \n in beginning of string

  • Thread starter Sandy Lewanscheck
  • Start date
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top