- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:07 AM
Hi,
I am trying to split the comma separated values in a field in the below format
Input field : 12; 56; 89
Expected Output: '12', '56', '89'
var r, input_field;
var s = input_field.split('; ');
for (var i = 0; i < s.length; i++) {
r.push(s[i]);
}
The result is showing as 12,56,89 but I want the result as '12', '56', '89'
Please help me with the script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:16 AM - edited 04-18-2023 03:25 AM
By default it should be string after splitting the content, but if you still want the single quotes there use below:
var input_field = "12;56;89";
input_field= input_field.split(";");
var arr= [];
for(var i = 0 ; i < input_field.length ; i++){
arr.push("'"+input_field[i] + "'");
}
alert(arr);
Please refer below screenshot:
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:16 AM - edited 04-18-2023 03:25 AM
By default it should be string after splitting the content, but if you still want the single quotes there use below:
var input_field = "12;56;89";
input_field= input_field.split(";");
var arr= [];
for(var i = 0 ; i < input_field.length ; i++){
arr.push("'"+input_field[i] + "'");
}
alert(arr);
Please refer below screenshot:
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:17 AM
Hello tanz,
I've tested this in my PDI, try if it works for you:
var input = '12; 56; 89';
var inputParsed = input.replace(/\s/g, ""); // Remove WhiteSpaces in input string
var arrAux = inputParsed.split(';');
var outArr = [];
for(var i = 0; i < arrAux.length; i++) {
var str = "'" + arrAux[i] + "'";
outArr.push(str);
}
//gs.info(outArr.join());
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 03:17 AM
Here you go:
var x = '12; 56; 89';
var y=[];
x = x.split(';');
for(i=0;i<x.length;i++)
{
y.push("'"+x[i]+"'");
}
alert(y.toString());