Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  55] [ 2]  / answers: 1 / hits: 18344  / 9 Years ago, mon, august 31, 2015, 12:00:00

Hi I have some text in following format,



683101,

682303,

682302,

682315,

683581,

686667,

682008,

683572,

683573,

682313,

686672,

683545 etc....



Each line break'ed into next line with Enter. I have nearly 2000 lines of text like this. i want o display the above string to a single line like this.


683101,
682303,
682302,
682315,
683581,
686667,
682008,
683572,
683573,
682313,
686672,
683545,
686672,
683545 etc..



I think there is some tweak options in CSS for doing this. Is there a way in JavaScript to do this? Actually it is not a requirement for me, am just curious to know how it is done.




  • Edit:



In My text editor it looks like this,


enter



When i try to run it, this is what i get.



enter



Thats why i want to remove the enter, multiline.......


More From » javascript

 Answers
29

I have a simple way for this. You can do this without extra code. Just write like this -


var str = "12345,
234234,
234324,
234324,
234324,
234234";

now just add a slash


Ok, If you don't want to use the above method then use another plan is -


take inside an array and after that use the join method


var str = [12345,
234234,
234324,
234324,
234324,
234234];


str.join(",");

If we are using ES6, Then we have an elegant way to do this using Backtick -


var str = `12345,
234234,
234324,
234324,
234324,
234234`;

[#65244] Thursday, August 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chelseyn

Total Points: 36
Total Questions: 85
Total Answers: 89

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;