Split and Write multiple lines in single cell

Hi All,

I have a column in excel “text”, i want to read the cell and split string at 30 character, without break a word and write it in a same cell in multiple line.
eg:
I have a text in single cell-
“UiPath Studio - an advanced tool that enables you to design automation processes in a visual manner, through diagrams.”

output i need in same cell is-
UiPath Studio - an advanced
tool that enables you to
design automation processes in
a visual manner, through
diagrams.

Regards,

Maybe something like this would work for you? You can use the pattern with the Matches activity.

\S.{1,29}(?=( |$))

but how to write this multiple line in a single cell in excel.

Hi @reetmehta

After spilting the word like above suggested by @ptrobot

Use assign activity to intialise a string let’s say output = “”

Use for each loop to loop through each item in collection obtained as result of spilting

inside the loop use assign activity like this

output = output+item+Environment.NewLine

After the loop use write cell activitiy to write the output on the cell

1 Like

You could use For Each as @NIVED_NAMBIAR suggested or you could also use LINQ and String.Join().

cellNewText = String.Join(vbLf.ToString, System.Text.RegularExpressions.Regex.Matches(inputString, "\S.{1,29}(?=( |$))").Select(Function(m) m.ToString).ToArray)

inputString should be the cell’s old text. The code converts the matches to an array and then joins them to a string with a line break in between.

2 Likes

Thanks @NIVED_NAMBIAR

Hi @ptrobot ,

i am getting error as"Select is not a member of ‘System.Text.RegularExpressions.MatchCollection’ "

Import the namespace System.Text.RegularExpressions and use this instead:

cellNewText = String.Join(vbLf.ToString, Regex.Matches(inputString, "\S.{1,29}(?=( |$))").OfType(Of Match)().Select(Function(m) m.ToString).ToArray)

The difference is that we have inserted OfType(Of Match)() in between matches() and select().

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.