I have a list with blank lines like this:
Apple
Banana
Peach
I want to remove the blank lines in the list so it’s like this:
Apple
Banana
Peach
How do I do that?
I’ve tried using replace(myList; newline; emptystring) and all kinds of variations like that, but when I do that, the output comes out like AppleBananaPeach all in a single line.
Welcome to the Make community!
Looks like you have to replace multiple newlines with a single newline. This only takes a single operation (or no extra operations if you are directly mapping it in a field).
{{ replace(1.myList; "/[\n\r]+/g"; newline) }}
This is because this contains two newlines, one at the end of Apple, and another on the blank line (which is why Banana is yet on another newline):
Apple
Banana
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
3 Likes
Hey @LaurenK The above solution seems correct but it will not work if you have Multiple nextlines.
For this input It will give


The solution which will deal with multiple lines
Output
The export Blueprint
blueprint (11).json (6.7 KB)
2 Likes
@VinayakUpadhyay You’re my hero! It worked!!! You rock! Thank you so much

1 Like
@VinayakUpadhyay I’m super curious - at which step are the empty strings from the line breaks removed?
Have you tried removing the extra line breaks in a single operation/step yet, like I mentioned above?
Example Text

Single Replace Function

Output

samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
Module Export
You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.
-
Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block

-
Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.
-
Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.
Expand Module Export Code
JSON
{
"subflows": [
{
"flow": [
{
"id": 57,
"module": "util:ComposeTransformer",
"version": 1,
"parameters": {},
"mapper": {
"value": "Apple\n\nBanana\n\nPear\n\n\n\nOrange\n\n\n\n\n\n\n\nWatermelon"
},
"metadata": {
"designer": {
"x": 11,
"y": -1334
},
"restore": {},
"expect": [
{
"name": "value",
"type": "text",
"label": "Text"
}
]
}
},
{
"id": 58,
"module": "util:SetVariable2",
"version": 1,
"parameters": {},
"mapper": {
"name": "output",
"scope": "roundtrip",
"value": "{{replace(57.value; \"/[\\n\\r]+/g\"; newline)}}"
},
"metadata": {
"designer": {
"x": 258,
"y": -1333
},
"restore": {
"expect": {
"scope": {
"label": "One cycle"
}
}
},
"expect": [
{
"name": "name",
"type": "text",
"label": "Variable name",
"required": true
},
{
"name": "scope",
"type": "select",
"label": "Variable lifetime",
"required": true,
"validate": {
"enum": [
"roundtrip",
"execution"
]
}
},
{
"name": "value",
"type": "any",
"label": "Variable value"
}
],
"interface": [
{
"name": "output",
"label": "output",
"type": "any"
}
]
}
}
]
}
],
"metadata": {
"version": 1
}
}
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
2 Likes