Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

JavaScript - Can I convert multiple string lines to single line?

Paul125
Kilo Guru

Hi - I want to convert below lines to single line. Is this something possible with JavaScript?

This is line one
This is line two
             This is a broken line
This is line three

Expected output:

This is line one, This is line two This is a broken line, This is line three
             
1 ACCEPTED SOLUTION

Try this out

var line = '';
var lines = multiLines.split("\n"); //multiLines contains your text
for(var i=0; i<lines.length; i++){
  if(lines[i].startsWith(" ")){
    line += " " + lines[i].trim();  
  }else{
    line += "," + lines[i].trim();  
      
  }    
}

line = line.substring(1).trim();

View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hi,

Can you try this script.

 

var line = '';
var lines = multiLines.split("\n"); //multiLines contains your text
for(var i=0; i<lines.length; i++){
  line += "," + lines[i].trim();  
}

line = line.substring(1);
gs.info(line);

 

Thanks!

Hi Mate,

 

I am stuck to a very strange problem and need your assistance. How to Compare between String Field and Multi Line Text Variable. I have a multi line text variable "ci_desc" and there is a CI short Description field "short_description".

There is a CI record having data like

Short Description : Enterprise Resource Planning - Commercial ERP
ERP in Russian

I can read those values properly but trying to check whether the values are equal or not. Inspite of they are being equal I am getting not matching alert. Please help.

Code Snippet:


if(gr1.short_description.replace(/\r?\n|\r/g, "") == ee.toString())
{
gs.log("match got");
}

Paul125
Kilo Guru

Thanks for the reply. This is working for me. Can I do something like below?

This is line one
This is line two
             This is a broken line
This is line three

Expected output:

This is line one, This is line two This is a broken line, This is line three

Try this out

var line = '';
var lines = multiLines.split("\n"); //multiLines contains your text
for(var i=0; i<lines.length; i++){
  if(lines[i].startsWith(" ")){
    line += " " + lines[i].trim();  
  }else{
    line += "," + lines[i].trim();  
      
  }    
}

line = line.substring(1).trim();