0
votes

I am working in UiPath Studio, this uses VB.NET . So i have a word document and i have to replace some texts. I have for example a new line than some text than a new line… and sometimes i need to delete that “some text” and i am ending up having a word document with like 3 new lines between some texts, so i have multiple texts and multimple lines… so this is approximetly what it’s look like:

Some text1

Some text2

Some text3

Some text4

.......

And then if i replace Some text2 with String.Empty i am getting this:

Some text1

\n

\n

\n

Some text3

Some text4

.......

And i want to look like this:

Some text1

Some text3

Some text4

.......

I have multiple "Some text" so i need a general method to work.

Imagine that \n is not there, it's a new line. I just used it because if i write multiple new lines stackoverflow deletes them.

I tried everything, i tried like 20 diffrent methods and nothing worked, it's gotta be something that works.

I tried a lot of these things and other alternatives:

System.Text.RegularExpressions.Regex.Replace(myText,"(\r\n|\r|\n)+", Environment.NewLine, System.Text.RegularExpressions.RegexOptions.Multiline)

But nothing worked.

1
You need to assign the Replace to a variable string output = Replace(string, pattern).Value;jdweng
A docx file? Not a text file? You're going to have to open it with some openxml library and see how it's structured. They might not be newlinrs at all, but separate paragraph objectsCaius Jard
Thank you @CaiusJard you are a genius, it was actually \r instead of \n. I had to replace "\r\r\r" with "". So i did System.Text.RegularExpressions.Regex.Replace(myText,"\r\r\r","").Jambor Norbert

1 Answers

0
votes

PagestringArray = PageString.Split({vbLf},StringSplitOptions.RemoveEmptyEntries)

this will remove \r, \a, \t etc

Send Hotkey "ctrl + a" Send Hotkey "ctrl + c" "Copy Selected Text" or "Get from clipboard" // fill the result field with the name of the variable that you are using to store the text for example: PageString

split 'PageString' to array of strings: Assign PagestringArray = PageString.Split({vbLf},StringSplitOptions.RemoveEmptyEntries)

foreach item in PagestringArray

ResultString = ResultString + item.toString + "\n"

:) Save the string to a file