Add break before specific word

Hi,

I have a text file and everything is in one line. I need to add break before specific word for example before “<Details”.

Example text:

HI @markosc

You can use <br> before <Details

Regards
Gokul

Yes, but how do I add it in existing file

Hi @markosc ,
read the test file and store it in a string variable “str” and then use split operation:
str.Split(“<”c) and put it in an array.
Then loop the array and for each item append Enviromnet.NewLine to each item.

Then put the array string into a normal string by appending inside another loop and print that string with some some string manipulation.
You will get your result.

I am attaching the sample workflow for your reference.
Main (4).xaml (10.1 KB)

Thanks & Regards,
Shubham Dutta

have a look at this regex approach:

for the substitution any needed string (e.g. <br>, Environment.NewLine, combinations… can be used

we also handle defensive any occurrences of spaces between the tags.

Pattern:
(?<=>)(\s*?)(?=<Details)

Regex Help: - Regex.Replace(…
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Hi @markosc

You can try with this expression

System.Text.RegularExpressions.Regex.Replace(YourString,"(?=<)|(?=< )","<br>").Tostring

Regards
Gokul

HI @markosc

Checkout this expression

System.Text.RegularExpressions.Regex.Replace(str,"(?<=>)","<br>")

image
image

Regards
Sudharsan

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