0

I've the data like

1

2

3

4

after I replace I should get the data as 1234 or 1 2 3 4.

I'm reading the content from one field and storing it one variable. I'm assigning the replaced value to one more variable.

I've tried using

var justiread=comments.read(); var result=justiread.replace(new RegExp( "/\r?\n|\r/", "g" ), ""); 

even after replacing I'm getting the same as I've entered.

If i want to do the same thing repeatedly say like 7 times. I'm using for loop but the same query is not working. any help pls

 for(h=1;h<=7;h++){ var addjusti=JUSTIFICATION.read(h); var addresult=addjusti.replace(/(\r\n|\n|\r)/gm," "); } 

but i'm unable to write it into the field

Anyone please help me out.

0

2 Answers 2

1
str.replace(/(\r|\n)/g,"") 

should do the trick.

\r and \n are not always together (depends on EOL style... unix/windows etc).

Sign up to request clarification or add additional context in comments.

Comments

0

Don't use new RegExp. Just use the string replace method.

justiread..replace(/(\r\n|\n|\r)/gm,"")

The "g" switch is global replace, "m" means it should happen more than once.

See http://www.textfixer.com/tutorials/javascript-line-breaks.php

2 Comments

m means something a bit different than that. Kinda totally different, in fact. :P Basically, it means that the string can be multiple lines, and ^ and $ match at the beginning and end of each line. If you don't have a ^ or $ in the pattern, it doesn't much matter.
If i want to do the same thing repeatedly say like 7 times. I'm using for loop but the same query is not working. any help pls

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.