Skip to main content

A tricky & alternative solution to split string at specified delimiter.


Thanks to KuanChiang Lui to provide this Trick.

 

Scenario: There have a string value (Delimiter strings) that returned from a data source or response value from a web request (SOAP or REST) and would like to split it and store into a dictionary.

 

Example Input

Text = “1,2,3,4,5,6,7,8,9,10‌”

 

Expected Output

Dictionary = i"1","2","3","4","5","6","7","8","9","10"]

 

Solutions: Check out the step by step below.

Pre-requisites: Create a Text Variable and set value with "1,2,3,4,5,6,7,8,9,10".

{Variable: String to Split} = 1,2,3,4,5,6,7,8,9,10‌

 

Step 1: Apply “Set Workflow Variables” action and configure to add XML node in between “String to Split”.

48592_pastedImage_0.png48687_pastedImage_2.png

 

Step 2: Apply “Replace Substring in String” action and configure to replace the delimiter “,” with XML node.

48692_pastedImage_6.png

The Output “String to Split” is becomes a valid XML as below.

<values>

                <value>1</value>

                <value>2</value>

                <value>3</value>

                <value>4</value>

                <value>5</value>

                <value>6</value>

                <value>7</value>

                <value>8</value>

                <value>9</value>

                <value>10</value>

</values>

 

Step 3: Apply “Query XML” action and configure to query the values into dictionary.

48693_pastedImage_8.png

48694_pastedImage_9.png

 

Result: Return the string in dictionary format

{Variable: Output in Dictionary} = "1","2","3","4","5","6","7","8","9","10"]


The enclosed attachment is the sample workflow that has been configured with steps above. You can import to Site workflow in Nintex Workflow Office 365.

 

Cheers!!!

Usable for CAML queries <Query><Where><In><FieldRef Name="..." /><Values><Value Type="...">...</Value>...</Values></In></Where></Query> from a LookupMulti value. I was considering to share this as well.

Seems like Regex is a bit more elegant and simpler to implement when you know how.



Hi Alexey Krasheninnikov

Thanks for sharing! I think this action(Regular expression) is not available in Nintex Workflow Office 365.


I didn't notice this was O365 space. Then, a [Learn More] blog post could still be welcome?


You can just use a Regex to split on the comma 😉 it's way easier


Reply