Hi
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”
string output=msg.Split(‘,’)
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?
string output=msg.Split()
or
string output=msg.Split(‘,’,StringSplitOptions.None)
Thanks
1 Like
Hey @Lokesh_Chandra
Split function cannot accept a single character instead a char array or with additional arguments.
Thanks
#nK
Lokesh_Chandra:
“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.
ppr
(Peter Preuss)
November 1, 2022, 5:59pm
4
give a try at
msg.Split(',');
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();
Hello,
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.
Hello Laurentiu_Mihai
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)
ppr
(Peter Preuss)
November 2, 2022, 1:30pm
7
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?
ppr
(Peter Preuss)
November 2, 2022, 4:20pm
9
can you share your XAML with us, if possible
Also let us know:
UiPath Studio Version
Selected Targetframework
Version Of UiPath.System.Activities Package
Thanks
Also give a try at this variation:
YourStringVar.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
3 Likes
You have to put the option settings like StringSplitOptions.RemoveEmptyEntries
1 Like
Manchu
(MK)
March 3, 2023, 9:59pm
11
Thank you so much , it helped me .
1 Like
Could you give me more information?
@Manchu you have to close the question before and open a new case with the floating robot.
Thank you