How to remove the blank lines from output?

Hi guys,

I’m asking first time here for solution please help me.

created the seq for scrapping the recipe’s ingredients. for this, I used the get full text activity but in output showing the lots of blank space between the ingredients.

please help me…

Hi @pratiksha_gulhane

Try this

filteredText = String.Join(Environment.NewLine, inputText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))

Or

filteredText = System.Text.RegularExpressions.Regex.Replace(inputText, "\s+", " ").Trim()

Regards,

just share with us some sample input e.g. use quickly the immediate panel and type in your variablename

Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

we would like to inspect as we have to replace multiple line breaks or multiple spaces …

Get Full Text is a classic activity. You should be working in modern.

Anyway, Get Text is probably not the best way to do this. Have you tried Table Extraction? For Each UI Element?

Hie @pratiksha_gulhane for scrapping the data you can use table extraction activity… any way btw. if your string value has blank space you can use Replace manipulation …
example - create a string variable -


image
image
str - input(your get text output).replace(" “,”")
cheers Happy Automation

I am not using the table extraction here. using the get full-text classic activity and dynamic selector.

I used the replace manipulation here but it still has no change.

@pratiksha_gulhane

Can you please provide input and expected output

Regards,

yeah, sure. I can share the current output ss here.

@pratiksha_gulhane

Try this

Input.ReplaceLineEndings(“”)

Regards,

1 Like

Give a try at

Assign activity:
strCleansed =

System.Text.RegularExpressions.Regex.Replace(yourTextVar, "[\r\n]+", Environment.NewlIne)

you can prototypw within the immediate panel

After that we can trim the multiple spaces by
strCleansed2 =

System.Text.RegularExpressions.Regex.Replace(strCleansed, "\ +", " ")

thank you. this code is working…

@pratiksha_gulhane

Try this

System.Text.RegularExpressions.Regex.Replace(Input, "\s+", Environment.NewLine)

Regards,

we stressed the scenario with

  • multiple spaces
  • multiple linebreaks
  • multiple linebreaks, spaces and tabs mixed:

and came up to this first cleansing pattern

Done in UiPath:

strText = System.Text.RegularExpressions.Regex.Replace(strText,"(\r?\n\s+)", Environment.NewLine)

For a cleansing on multiple spaces we can do afterwards
grafik

strText = System.Text.RegularExpressions.Regex.Replace(strText,"(\ +)", " ")

When text comes from web extractions then maybe we would also cleanse all non-breakable spaces ( chr(160) ) in advance

output showing below

thanks for code @ppr
solution -
strText = System.Text.RegularExpressions.Regex.Replace(strText,“(\r?\n\s+)”, Environment.NewLine)

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