Hi,
I want to remove extra characters present from a certain column in datable by not using for each row activity.
For example in the below Role column which should be fixed to 5 characters
Hi,
I want to remove extra characters present from a certain column in datable by not using for each row activity.
For example in the below Role column which should be fixed to 5 characters
Please try this in invoke code …send dt as in/out argument
Dt.AsEnumerable.ToList.ForEach(sub(r) r("Role") = If(r("Role").ToString.Length>5,r("Role").ToString.SubString(0,5),r("Role").ToString))
Cheerd
=> Use Read Range Workbook to read the excel and store it in an datatable say dtInput
Input:
dtOutput = dtInput.Clone()
For Each row As DataRow In dtInput.Rows
Dim newName As String = row("Name").ToString()
Dim role As String = row("ROLE").ToString()
If role.Length > 5 Then
row("ROLE") = role.Substring(0, 5)
End If
dtOutput.ImportRow(row)
Next
=> Below are the invoked arguments:
dtOutput
to excel.Workflow:
Hope it helps
Hey @karthik_kulkarni1
you can use it:
newDataTable = originalDataTable.Clone()
newDataTable = originalDataTable.AsEnumerable().Select(Function(row) newDataTable.LoadDataRow(new Object() {row.Field(Of String)(“Name”), row.Field(Of String)(“ROLE”).Substring(0, Math.Min(5, row.Field(Of String)(“ROLE”).Length))}, False)).CopyToDataTable()
Here is a project example: BlankProcess59.zip (9.1 KB)
You can simply use below LinQ Query
DT.AsEnumerable().Select(Function(row) DT.Clone().LoadDataRow({
row.Field(Of String)("Name"),
If(row.Field(Of String)("Role").Length > 5, row.Field(Of String)("Role").Substring(0, 5), row.Field(Of String)("Role"))
}, False)).CopyToDataTable()
Input:
Output:
Cheers!!
thing is above is working but it is eliminating other columns I have more number of columns.
Could you try the following?
Code:
DT.AsEnumerable().ToList().ForEach(Sub(row)
row.SetField("Role", If(row.Field(Of String)("Role").Length > 5, row.Field(Of String)("Role").Substring(0, 5), row.Field(Of String)("Role")))
End Sub)
Input:
Output:
Cheers!!
You can try this too. This should work.
Happy to help if not sorted.
Regards
As per formula it eould not remove any columns…
Please check it properly…the formula is only to update
Cheers
Hi @karthik_kulkarni1
Check out the below process n Studio X. This should help you.
RemoveExtraCharacters.zip (233.6 KB)
Hope this helps you.
Happy Automation
Regards