- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 06:59 PM
I have a string such as the following:
Tour CB21, 16 Place de I`Iris
Via San Simpliciano 1
abc
xyz
pqr
I want to remove all line breaks from this string so that it looks like this:
Tour CB21, 16 Place de I`Iris Via San Simpliciano 1 abc xyz pqr
I tried following code:
myString = myString.replace(/\n\s*\n/g, " ");
The max it does is:
Tour CB21, 16 Place de I`Iris Via San Simpliciano 1 abc xyz pqr
How do i bring the string in a single line ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 08:04 PM
try this,
myString = myString.replace(/(\r\n|\n|\r)/gm,"").replace(/ {1,}/g," ");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 07:04 PM
I tried this also:
myString = myString .replace(/\n/g, "");
but it doesn't bring the string together in a single line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 07:42 PM
Can you check what the below code is giving. What is the source of your string?
myString = myString.toString();
gs.print(myString);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 08:04 PM
try this,
myString = myString.replace(/(\r\n|\n|\r)/gm,"").replace(/ {1,}/g," ");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 10:40 PM
Hi Shishir,
Thank you for your reply.
Following line worked:
myString = myString.replace(/(\r\n|\n|\r)/gm,"");
Kind Regards,
Vineetha