473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

strip <br> and \n in beginning of string

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

Jul 20 '05 #1
1 1632
JRS: In article <3f**********@news.bluewin.ch>, seen in
news:comp.lang.javascript, Sandy Lewanscheck <ze***@nurfuerspam.de>
posted at Wed, 7 Jan 2004 16:18:26 :-
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."
S = S.replace(/^(<br>|\n)+/, "") // ??
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?


No.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
7
by: noor.rahman | last post by:
I have an XML file that stores data from an HTML form. I use XSL to display the data in HTML format. The data may have newline characters. However, XSL is not displaying the newlines properly in...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
2
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all...
1
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all...
4
by: Christofer Dutz | last post by:
Hi, I am having a small problem, that is driving me nuts. My application reads some Xml and runs 2 Xsl Transformations to generate HTML. As soon as my second XSL introduces some <br/tags, the...
2
by: xhe | last post by:
I met a very headache problem in javascript, I think this might be difference between IE and NS / Safari. I have a text area <form> <textarea name='tex1' onkeyup='displayit();'></textarea>...
7
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.