How to Split a String

studio
variable
string

#1

I am trying to split a string on string ‘not’ . String is “This is not a game” is in variable PDFVariable. So I use a variable Var of type String[] and assign as PDFVariable.ToString().Split(‘not’) and trying to see the output in Var(1). But I am getting error in the Assign box.


Extracting letters from a word/string
How to split at 4 consequent spaces?
#2

Can you send what error message are you getting when u hover on the blue warning.

May be you cannot use Var as a variable,try something else.


#3


#4

Did you try double quotes for not instead of single?

–> “not”


#5

Does not work on “not”


#6

Hi Sampad ,

use can use
Split(PDFvariable.tostring,“not”)

or you can use “Split string” activity in Expressions


How to split data using UiPath studio activities?
#7

Thanks Uday !! Works fine !


#8

Hi @sampaddas,

You can try this StringVaraible.Split({“not”},StringSplitOptions.None)

Thanks,
Vikas Reddy :slight_smile:


How to split data using UiPath studio activities?
#9

Variable.Split({“not”},StringSplitOptions.None)…Try with this This will work…


#10

Hi!

I have a similar problem also, and I cannot get it to work with these tips. I would have to split a string by empty lines. Heres an example of a string:

Name 2
Name 345
Name 1

Name 1
Name 2
Name 3
1234

So, I would have to split it from where ever there’s an empty line. So it would become two strings:

Name 2
Name 345
Name 1

and

Name 1
Name 2
Name 3
1234.

I tried intructions from here: https://stackoverflow.com/questions/32429967/how-do-i-split-a-string-on-an-empty-line-using-split
but I could not get it to work with UiPath. I tried
text.Split({"\r\n\r\n"},stringsplitoptions.None)
but it doesn’t work.

Anyone have an idea what could I do? Expertise would be appreciated! Thank you very much!


#11

Actually I got this to work!

text.Split({Environment.NewLine + Environment.NewLine},stringsplitoptions.none)

So, Environment.NewLine works atleast on a .txt file.


#12

you can use

text.Split(new string[ ] {Environment.NewLine + Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

The combined Environment.NewLine + Environment.NewLine as this will only split when a new line is also followed by a new line and split accordingly.

String[ ] people = text.Split(new string[] { “\r\n\r\n” },StringSplitOptions.RemoveEmptyEntries);

This will also work.

Regards…!!
Aksh


How to split data using UiPath studio activities?
#13

Okay, thank you much!


#14

there is a split activity… we can specify the property based on which we should split like space, tab or new line… if we use that activity it will be easy no need of coding required…


String splitting advice does not work
#15

I know this is a old post, however I was stuck in split string and was working on resolution which I wanted to share. I wanted to get the file name using the “Path.GetFileName” function into a single variable. the sample workflow works fine, you just need to specify the complete path along with the file name under “Path.GetFileName” function. Sample uploaded.Get_FileName_String_Split.zip (2.2 KB)


#16

I don’t see a “Split” activity in my list.

For the love of god… splitting a string shouldn’t be so nuanced that it requires this much discussion :-/

Given SomeString contains a multi-word string, I tried simply using the Assign activity to assign SomeString.Split(" ") to a string array variable… and I keep getting the an error “Option Strict On disallows implicit conversions from string to char”.

I ended up having to Google the error message and change my approach to SomeString.Split(Convert.ToChar(" "))


#17

Yeah, the Split function requires a character or character array.
Alternatively you can use ‘c’ or (0) to indicate that it’s a character.
SomeString.Split(" "c) or SomeString.Split(" "(0))

You can also use a string wtih brackets to make it an array.
SomeString.Split({" "},System.StringSplitOptions.None)
and the string can be anything. System.StringSplitOptions.RemoveEmptyEntries will also get rid of empty items.

Hope that gives you some additional info!
Thanks.


#18

Thanks!

I don’t use VB much so I totally missed the () after String in this signature. That definitely clears it up.

split


#19

hi

actual str=“123-456-6789”

i need to split like this dynamically

str1="123"
str2="456"
str3=“6789”

pls send me how to split and save it to another variable


#20

Hello @Venkatp,

You can use Microsoft.Activities.Expressions.SplitString Activity or String.Split Method. In both cases the result is an array of strings

SplitStringActivity.xaml (5.9 KB)
SplitStringAssign.xaml (6.1 KB)

https://msdn.microsoft.com/en-us/library/system.string.split(v=vs.110).aspx

Regards,
Susana