How to replace special characters with new line?

activities
studio

#1

I am new user of UiPath. I am trying to use it to do some file processing but I get stuck when to replace $ with new line.

I use “Read Text File” activity to read the data(aaa$$$bbb) from text file and store into variable. Then I use “Replace” activity with Input as the variable, pattern as “$”, and replacement as “\n”. I am not sure can \n use to create new line.

The result I get is aaa$$$bbb\n
The expected result I want is
aaa

bbb
Can I know which part of the process had been done wrongly? Thanks


#2

Hello @hytong,

You can use Environment.NewLine

Take a look at this:

Regards,
Susana


#3

@Susana Wow thanks! It’s work for Create New Line. But still cannot replace the dollar sign $, any advice?

I’d try with other special character like @ and it got no problem.


#4

Hello @hytong,

You can use text.Replace("$",Environment.NewLine) or text.Replace(Chr(36),Environment.NewLine)

This works for me:

Regards,
Susana


#5

@Susana Thanks. I’ve try it and I can see the expected result in console. But when I add another “Message box” to show the “text” right after the “Write Line” action done, I am still getting aaa$$$ccc.


#6

Hey @hytong,

Try to use Assign activity

Regards,
Susana


#7

@Susana Yes it solved! Thanks a lot.

But personally I think the “Replace” activity is weird as it can be use for other special character but not $.


#8

How to perform subString operation using IndexOf for “=” character.

item.Substring(item.IndexOf("=")+2) is throwing validation error.

Apologize if this is not the right way to raise a query.

Thanks in advance.