String splitting advice does not work

Hi everybody,

I am trying a simple thing, which has already been discussed here, however, the proposed solutions seem not to work for me.

Basically, I am copying the body from an email message “mail” into a string, using the trivial “mail.Body” command and assigning that to a string - let’s call that “MyString”.

Now, I am trying to split “MyString” into pieces according to empty lines, assigning it to a new string “MySplitString” by “MyString.Split(…)”. The forum contains a lot of good advice (see e.g. here “How to Split a String - #14 by Divyashreem” or “Split string get text”).

However, none of the commands suggested there seems to work in my case. My UiPath Studio would always give error messages, e.g.:

“MyString.Split(System.Environment.NewLine)” → “Option Strict On disallows implicit conversions from ‘String’ to ‘Char’.”
“MyString.Split(Convert.ToChar(System.Environment.NewLine))” → “Cannot assign from type ‘System.String’ to type ‘UiPath.Core.GenericValue’ in Assign activity ‘Assign’.”
“MyString.Split(new string {Environment.NewLine + Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)” → “Identifier expected”.

I am very sorry for resurrecting this topic, but the suggested solutions seem to either not work in my case (and I don’t understand why) or, which is an option, I am too stupid to convert the solutions suggested to my case - even though I can’t see where I am failing.

May this be an issue caused by newer versions of UiPath, given that the proposed solutions are about 1 year old?

Can anybody enlighten me?

Thanks a lot, and sorry again if I have overlooked something.

Alex

Hey @AlexM82

you can split like this :slight_smile:

data.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries)

Sample:- Substring sample.xaml (8.2 KB)

Regards…!!
AKsh

Dear Aksh,

thanks a lot, you really seem to be a master at this! :slight_smile:

I did how you advised and, indeed, I do not anymore receive any error messages. I can also declare the result to be an array of strings and, as expected, sending a message box of its zeroth entry returns the first line of the mail message (say, “Hello friends,”).

Thanks a lot!!

Alex