如何在逻辑应用或Power Automate中添加换行?

huangapple go评论106阅读模式
英文:

how can I add a newline using logic app or powerautomate?

问题

我正在尝试在Logic App中使用字符串添加换行符。但我没有得到有趣的结果。

这是我得到的:

ios-youtube,
keepassium-ios,
markmcguill-strongbox,
Office-Word,
microsoft-azureauthenticator,
microsoft-scmx,
Office-Excel,
microsoft-skydrive,
Office-Powerpoint,
spotify-client,
Office-Word,
microsoft-onenote,
uhhhmagazine-flannl,
robbie-HomeAssistant,
rdc-ios,
microsoft-skydrive,
skype-teams,
miketigas-OnionBrowser,
netflix-Netflix,
bjoerndemming-aldisued,
delius-klasing-bike-app,
delius-klasing-tour,
heise-ch-magazine,
heise-ct-magazine,
heise-news4,
online-norma,
sec-lidl,
delius-klasing-ios,
robbie-HomeAssistant

我尝试了这些。

如何在逻辑应用或Power Automate中添加换行?

如何在逻辑应用或Power Automate中添加换行?

我想要结果以这种形式呈现。

- ios-youtube,
- keepassium-ios,
- markmcguill-strongbox,
- Office-Word,
- microsoft-azureauthenticator,
- microsoft-scmx,
- Office-Excel,
- microsoft-skydrive,
- Office-Powerpoint,
- spotify-client,
- Office-Word,
- microsoft-onenote,
- uhhhmagine-flannl,
- robbie-HomeAssistant,
- rdc-ios,
- microsoft-skydrive,
- skype-teams,
- miketigas-OnionBrowser,
- netflix-Netflix,
- bjoerndemming-aldisued,
- delius-klasing-bike-app,
- delius-klasing-tour,
- heise-ch-magazin,
- heise-ct-magazin,
- heise-news4,
- online-norma,
- sec-lidl,
- delius-klasing-ios,
- robbie-HomeAssistant
英文:

I'm trying to add newline in String using Logic App. But I got nothing interesting.

That is what I got:

ios-youtube, keepassium-ios, markmcguill-strongbox, Office-Word, microsoft-azureauthenticator, microsoft-scmx, Office-Excel, microsoft-skydrive, Office-Powerpoint, spotify-client, Office-Word, microsoft-onenote, uhhhmagine-flannl, robbie-HomeAssistant, rdc-ios, microsoft-skydrive, skype-teams, miketigas-OnionBrowser, netflix-Netflix, bjoerndemming-aldisued, delius-klasing-bike-app, delius-klasing-tour, heise-ch-magazin, heise-ct-magazin, heise-news4, online-norma, sec-lidl, delius-klasing-ios, robbie-HomeAssistant

I tried these.

如何在逻辑应用或Power Automate中添加换行?

如何在逻辑应用或Power Automate中添加换行?

and I want the result in this form.



- ios-youtube, 
- keepassium-ios, 
- markmcguill-strongbox, 
- Office-Word, 
- microsoft-azureauthenticator,
- microsoft-scmx, Office-Excel,
- microsoft-skydrive, 
- Office-Powerpoint, 
- spotify-client, 
- Office-Word, 
- microsoft-onenote, 
- uhhhmagine-flannl, 
- robbie-HomeAssistant, 
- rdc-ios, 
- microsoft-skydrive, 
- skype-teams, 
- miketigas-OnionBrowser, 
- netflix-Netflix, 
- bjoerndemming-aldisued, 
- delius-klasing-bike-app, 
- delius-klasing-tour, 
- heise-ch-magazin, 
- heise-ct-magazin, 
- heise-news4, 
- online-norma, 
- sec-lidl, 
- delius-klasing-ios, 
- robbie-HomeAssistant

答案1

得分: 1

这个基本流程向您展示了一个相当简单的方法,应该能够帮助您完成任务。

流程

如何在逻辑应用或Power Automate中添加换行?

第二步中的表达式如下(请注意图像中起始处的连字符,以适应第一条记录)...

replace(variables('String'), ', ', ',\n- ')

...但当我输入它时,我是这样放入的...

replace(variables('String'), ', ', ',\n- ')

要实现这一点,您需要进入代码视图并编辑定义,将\\n更改为\n。原因是,通过设计器输入时,它并不是您想要的。代码视图如下...

"Initialize_Enhanced_String": {
    "inputs": {
        "variables": [
            {
                "name": "Enhanced String",
                "type": "string",
                "value": "- @{replace(variables('String'), ', ', ',\n- ')}"
            }
        ]
    },
    "runAfter": {
        "Initialize_String": [
            "Succeeded"
        ]
    },
    "type": "InitializeVariable"
}

...但这是不正确的。移除第二个斜杠将帮助您顺利完成任务。

结果

如何在逻辑应用或Power Automate中添加换行?

英文:

This basic flow shows you a fairly simple approach that should get you over the line.

Flow

如何在逻辑应用或Power Automate中添加换行?

The expression in the second step looks like this (noting the hyphen at the start in the image to cater for the very first record) ...

replace(variables('String'), ', ', ',
- ')

... but when I entered it, I put it in like this ...

    replace(variables('String'), ', ', ',\n- ')

To achieve that, you need to go into the Code View and edit the definition and change \\n to \n. Reason being, when you enter it through the designer, it's not what you're after. The code view will looks like this ...

"Initialize_Enhanced_String": {
    "inputs": {
        "variables": [
            {
                "name": "Enhanced String",
                "type": "string",
                "value": "- @{replace(variables('String'), ', ', ',\\n- ')}"
            }
        ]
    },
    "runAfter": {
        "Initialize_String": [
            "Succeeded"
        ]
    },
    "type": "InitializeVariable"
}

... and that isn't correct. Remove the second slash will get you across the line.

Result

如何在逻辑应用或Power Automate中添加换行?

答案2

得分: 0

在我的环境中,我已经复制并获得了以下预期结果:

设计:

如何在逻辑应用或Power Automate中添加换行?

然后初始化了一个空变量和由split(variables('var1'),',')组成的变量1:

如何在逻辑应用或Power Automate中添加换行?

然后在ForEach循环中输入了(compose 1输出),然后在操作中使用了composeconcat('- ',items('For_each'))中的concat,然后附加了var2,然后使用新行连接它(只需按Enter键):

如何在逻辑应用或Power Automate中添加换行?

输出:

如何在逻辑应用或Power Automate中添加换行?

如何在逻辑应用或Power Automate中添加换行?

代码视图:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@split(variables('var1'),',')",
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "var2",
                            "value": "@outputs('Compose_2')"
                        },
                        "runAfter": {
                            "Compose_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    },
                    "Compose_2": {
                        "inputs": "@concat('- ',items('For_each'))",
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@outputs('Compose')",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var1",
                            "type": "string",
                            "value": "ios-youtube, keepassium-ios, markmcguill-strongbox, Office-Word, microsoft-azureauthenticator, microsoft-scmx, Office-Excel, microsoft-skydrive, Office-Powerpoint, spotify-client, Office-Word, microsoft-onenote, uhhhmagine-flannl, robbie-HomeAssistant, rdc-ios, microsoft-skydrive, skype-teams, miketigas-OnionBrowser, netflix-Netflix, bjoerndemming-aldisued, delius-klasing-bike-app, delius-klasing-tour, heise-ch-magazin, heise-ct-magazin, heise-news4, online-norma, sec-lidl, delius-klasing-ios, robbie-HomeAssistant"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var2",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Join": {
                "inputs": {
                    "from": "@variables('var2')",
                    "joinWith": "\n"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Join"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
英文:

I have reproduced in my environment and got expected results as below:

Design:

如何在逻辑应用或Power Automate中添加换行?

Then initialized an empty variable and the composed variable 1 with split(variables('var1'),','):

如何在逻辑应用或Power Automate中添加换行?

Then in ForEach loop taken input (compose 1 output) then in action used concat in composeconcat('- ',items('For_each')) and then appended var2 and then joined it with new line(just press enter):

如何在逻辑应用或Power Automate中添加换行?

Output:

如何在逻辑应用或Power Automate中添加换行?

如何在逻辑应用或Power Automate中添加换行?

Codeview:

{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@split(variables('var1'),',')",
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "var2",
"value": "@outputs('Compose_2')"
},
"runAfter": {
"Compose_2": [
"Succeeded"
]
},
"type": "AppendToArrayVariable"
},
"Compose_2": {
"inputs": "@concat('- ',items('For_each'))",
"runAfter": {},
"type": "Compose"
}
},
"foreach": "@outputs('Compose')",
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "var1",
"type": "string",
"value": "ios-youtube, keepassium-ios, markmcguill-strongbox, Office-Word, microsoft-azureauthenticator, microsoft-scmx, Office-Excel, microsoft-skydrive, Office-Powerpoint, spotify-client, Office-Word, microsoft-onenote, uhhhmagine-flannl, robbie-HomeAssistant, rdc-ios, microsoft-skydrive, skype-teams, miketigas-OnionBrowser, netflix-Netflix, bjoerndemming-aldisued, delius-klasing-bike-app, delius-klasing-tour, heise-ch-magazin, heise-ct-magazin, heise-news4, online-norma, sec-lidl, delius-klasing-ios, robbie-HomeAssistant\n"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "var2",
"type": "array"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Join": {
"inputs": {
"from": "@variables('var2')",
"joinWith": "\n"
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Join"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

huangapple
  • 本文由 发表于 2023年7月20日 20:21:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729816.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定