Printing 3 words in a line

Hello guys,

I want to print 3 words in a line from a sentence.

Example:
Input: Hello I can do the automation I live in Chennai.

Output: Hello I can
do the automation
I live in
Chennai.

Hi @MAHESH_R2

Try this syntax:

input = "Hello I can do the automation I live in Chennai."

words = input.Split({" "}, StringSplitOptions.RemoveEmptyEntries)

output = String.Join(Environment.NewLine, Enumerable.Range(0, CInt(Math.Ceiling(words.Length / 3.0))).Select(Function(i) String.Join(" ", words.Skip(i * 3).Take(3))))

Hope it helps!!

1 Like

Hi @MAHESH_R2

You can use the LINQ Expression to split 3 words into each line.

- Assign -> InputString = "Hello I can do the automation I live in Chennai."

- Assign -> OutputString = String.Join(Environment.Newline, InputString.Split(" "c).Select(Function(word, index) New With { Key .Word = word, Key .Index = index \ 3 }).GroupBy(Function(x) x.Index).Select(Function(g) String.Join(" ", g.Select(Function(x) x.Word))).ToList())

Check the below workflow for better understanding,

Hope it helps!!

1 Like

@Parvathy @mkankatala

Thank you for the help it worked.

Regards

  • Mahesh
2 Likes

The RegEx way:

It’s my pleasure… @MAHESH_R2

Happy Automation!!

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