I’m trying to Limit/Trim a data column from zero to 50, without using For each loop. I’m using an Invoke Code with this:
dt.AsEnumerable().ToList.ForEach(Sub(row) row(0)=row(0).ToString.SubString(0,50))
Where it would substring the datas to 5. Problem is most of rows that are either empty or is less than 50. Is there a way to trim it without using for each loop?
lakshman
(Ganta lakshman)
April 27, 2022, 7:57am
2
@Shinjid
Try below expression.
dt.AsEnumerable().ToList.ForEach(Sub(row) If(row(0).ToString.Trim.Length > 50,row(0).ToString.Trim.SubString(0,50),row(0).ToString.Trim))
Invoke code: No compiled code to run
error BC30198: ‘)’ expected. At line 1
I’ve added another ‘)’ in the end, still the same
lakshman
(Ganta lakshman)
April 27, 2022, 8:30am
4
@Shinjid
Did you try the above expression ?
Except for the missing parenthesis, you need an assign statement also, since you are using a Sub().
dt.AsEnumerable().ToList.ForEach(Sub(row) row(0) = If(row(0).ToString.Trim.Length > 50, row(0).ToString.Trim.SubString(0,50), row(0).ToString.Trim))
ushu
(Usha kiranmai)
April 27, 2022, 8:52am
6
@Shinjid Try with the attached workflow. The code is in a notepad, we can call using invoke VBA. Just pass the range from UiPath
Example.zip (10.9 KB)
Yoichi
(Yoichi)
April 27, 2022, 9:09am
7
HI,
FYI, Another solution:
If you use VB.net in Invoke code, the following will work.
dt.AsEnumerable().ToList.ForEach(Sub(row) row(0)=Left(row(0).ToString(),50))
Regards,
1 Like
You mean put the code to an assign activity? I tried this before, but it gives “Expression does not produce a value” I had similar code but with string replace instead, and it only works on mine if I put it in Invoke Code.
Just use the expression I provided. I have corrected it for you.
dt.AsEnumerable().ToList.ForEach(Sub(row) row(0) = If(row(0).ToString.Trim.Length > 50, row(0).ToString.Trim.SubString(0,50), row(0).ToString.Trim))
1 Like
Thanks! This works now in Invoke Code.
1 Like
system
(system)
Closed
April 30, 2022, 9:14am
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.