I am using C# and I am facing issue in simple string manipulation.
The below code shows error as:
An expression tree may not contain a call or invocation that uses optional arguments
string msg=“UiPath, RPA, Robotics”
This does not makes sense as the same code works fine when you write the same in any other C# editor.
I know i can simply write any of the below and it will work but why the above is not working? Any suggestions?
Split function cannot accept a single character instead a char array or with additional arguments.
“UiPath, RPA, Robotics”
So going by your suggestion only I ran the my code here:
String.Split Method (System) | Microsoft Learn
I get the expected result.
But the same approach does not work in UIPath.
give a try at
as ’ is indicating that the split char is to interpret as a char
when the trimmed values are to return:
msg.Split(',').Select(x => x.Trim()).ToArray();
The variableName.Split method is kind of bugged in some cases.
Instead of using variableName.Split(delimiter), use the following: Split(variableName, delimiter)
This will always work without errors.
with VB your solution works but with C# it didn’t work for me (it’s more that method I can’t call it in an assing) so I recommend that if you have a phrase that you want to separate by a string you have to use yes or yes StringSplitOptions.RemoveEmptyEntries option in such a way that when using this formula it will remove the empty entries and it will work without problem using “,” as String.
If you don’t have to transform the separator to type char.
Main.xaml (8.7 KB)
project.json (1.5 KB)
we crosschecked within the immediate panel and it was working:
we checked within assign which also was working:
Any differences in your end-specific modeling?
can you share your XAML with us, if possible
Also let us know:
UiPath Studio Version
Version Of UiPath.System.Activities Package
Also give a try at this variation:
You have to put the option settings like StringSplitOptions.RemoveEmptyEntries