Get (partially) ride of Text in datatable

Hello, I just start using UIpath

I ran into a small problem,
I have datascraped a website and have saved the data to a csv file.
The csv file contains 1 column called ‘Sale’ (header) the data under this contains a 10%

example of how the Csv looks:
10 %

My question is, How can I get ride of the (spacebar) and %

If you always have the last two characters as " %" then you can take the substring of the sale value.

string = string.substring(0, string.Length-2)
where string is the “10 %” string will remove the last two characters from the string.

Hi Ultiseeker,

1.Read the csv to a datatable.
2.Inside the for each row activity for datatable,
assign, row("Sale") = System.Text.RegularExpressions.regex.Replace(row("Sale").ToString,"\s?%",string.Empty)
3. Write the datatable to file.


Looks like it doesn’t work, it gives the ‘one or more childeren have validation errors or warnings’ message.

At least the csv is now in a datatable (I got that working thanks)

can you show me a screenshot of how it would look like in UIpath?

Hi @Ultiseeker,

Sorry, I don’t noticed this.
Please find the workflow Remove_%_in_cell.xaml (6.7 KB)
and just change the filepath of ‘Read CSV’ and ‘Write CSV’ activites with your files.

I hope you know about reading csv file to datatable and writing it back.
The expression row("Sale") =System.Text.RegularExpressions.regex.Replace(row("Sale").ToString,"\s?%",string.Empty)
This regular expression checks for the presence of ‘space(optional) followed by % ’ in each cell under the header ‘Sale’ and replace it with a null value. Thus the ’ %’ will be deleted.
I hope you got it. Feel free to ask If you have any doubts. Happy automation.:grinning:

Warm regards,

1 Like

Thanks, It works.

Follow up question, is it possible that the ‘new csv’ file contain’s more than 1 line

for example
10 (first time datascrape)
15 (second time datascrape (because the sale went up))
5 (3rd data scrape)

Hi Ultiseeker,

Yes. It is possible. Please replace the ‘Write CSV’ activity with “Append To CSV” activity and use the same file name. It will append the values on each execution.

Warm regards,

Thank you very much.
Last question, Is it possible to add a column that is called ‘week’
so it goes like:

Sale, Week
10, 1