Hello Everyone! I am currently building a robot that needs scraping data table from the websites.
Now I have the data table scrapped but some of the value are too messy. May I know how I can use the for each row activity to retrieve every cell value of the column “USD” so that I can perform string manipulation to remove all extra texts.
Hey @Komom , could you please let us know exactly what are the extra texts you want to remove from the table under the USD Column? We can then also help you on finding a solution through string manipulations or Regex.
Meanwhile I can guide you one how you can use the For Each Row Activity:
Search the For Each Row in Data Table Activity in the activity panel and drag it on to your sequence.
Next you will need to specifiy the datatable you want to iterate over. For example, let’s say you have read the Financial Data.xlsx file and have stored that data into a datatable variable named dt_financialData, then you can add this datatable in to the For Each Row in Data Table activity in this manner:
So the activity will convert the datatable into Enumerable rows through which you can then access the values in the table. Now if you want to access each value from under the column USD, then inside the loop you can make use of this expression i.e. CurrentRow(“USD”).ToString
This is just a gist of how to use the For Each Row in Data Table activity.
Let us know if you need any help regarding the String Manipulations.
Thank you so much for your help! Basically I just want the first line of every cell under the USD “column”
For example, there is a super long description for “Revenue” start from the second line in the cell and I want to remove it is unnecessary and also making the cell unreadable.
I’ve understood what you’re trying to achieve. We can achieve by making use of the .Split method. We can Split the content (String) into an array of substrings using newline characters as delimiters.
The Expression to use: CurrentRow("(USD)").ToString.Split(Environment.NewLine.ToCharArray).First
This retrieves the data in the current row under the column USD data as a string, splits it into an array at each newline, and returns the first substring
You can make use of this expression in the assign block activity in the following manner:
Alternatively, I’d recommend you try using LINQ. You can achieve the same in just one assign block.
Make use of the following LINQ:
(From row In dt_financialData
Let usd=row("(USD)").ToString.Split(Environment.NewLine.ToCharArray).First
Select dt_financialData.Clone.Rows.Add({CType(usd,Object)}.Concat(row.ItemArray.Skip(1)).ToArray)).CopyToDatatable
Hi @lrtetala Actually I just found a problem: As the currency is not always USD, but the data I need to manipulate must be at the first column. May I know how can I change to specify the first column instead of fixing it to the “USD” column?