# How to Split a String

**URL:** <https://forum.uipath.com/t/how-to-split-a-string/2098>\
**Category:** Help\
**Tags:** variable, string, studio, system, activities\
**Created:** [March 6, 2017, 3:02am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098 "2017-03-06T03:02:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sampaddas](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sampaddas](https://forum.uipath.com/u/sampaddas)\
**Post date:** [March 6, 2017, 3:02am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/1 "2017-03-06T03:02:24Z")

</div>

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.

![](https://global.discourse-cdn.com/uipath/original/2X/1/1adbb1c7b5c34e9ba013b92eca6f9411bac207f4.png)

---

<div class="post-metadata">

**Author:** ![vvaidya](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vvaidya](https://forum.uipath.com/u/vvaidya)\
**Post date:** [March 6, 2017, 3:09am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/2 "2017-03-06T03:09:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sampaddas](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sampaddas](https://forum.uipath.com/u/sampaddas)\
**Post date:** [March 6, 2017, 3:22am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/3 "2017-03-06T03:22:12Z")

</div>

![](https://global.discourse-cdn.com/uipath/original/2X/0/05c8f08c0121a1a3e0d471588bc2f02d53710660.png)

---

<div class="post-metadata">

**Author:** ![vvaidya](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vvaidya](https://forum.uipath.com/u/vvaidya)\
**Post date:** [March 6, 2017, 3:35am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/4 "2017-03-06T03:35:51Z")

</div>

Did you try double quotes for not instead of single?

→ “not”

---

<div class="post-metadata">

**Author:** ![sampaddas](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sampaddas](https://forum.uipath.com/u/sampaddas)\
**Post date:** [March 6, 2017, 3:39am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/5 "2017-03-06T03:39:46Z")

</div>

Does not work on “not”

---

<div class="post-metadata">

**Author:** ![UdayKumar](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/udaykumar/32/182_2.png) [@UdayKumar](https://forum.uipath.com/u/UdayKumar)\
**Post date:** [March 6, 2017, 4:41am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/6 "2017-03-06T04:41:48Z")

</div>

Hi Sampad ,

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

or you can use “ **Split string** ” activity in Expressions

---

<div class="post-metadata">

**Author:** ![sampaddas](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sampaddas](https://forum.uipath.com/u/sampaddas)\
**Post date:** [March 6, 2017, 4:52am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/7 "2017-03-06T04:52:03Z")

</div>

Thanks Uday !! Works fine !

---

<div class="post-metadata">

**Author:** ![vikas\_reddy\_Vicky](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vikas_reddy_vicky/32/82_2.png) [@vikas\_reddy\_Vicky](https://forum.uipath.com/u/vikas_reddy_Vicky)\
**Post date:** [March 7, 2017, 2:00pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/8 "2017-03-07T14:00:54Z")

</div>

Hi @sampaddas,

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

![](https://global.discourse-cdn.com/uipath/original/2X/0/0cd49d1c01290b2b2bdcc6944032a9431f5de374.png)

Thanks,  
Vikas Reddy 🙂

---

<div class="post-metadata">

**Author:** ![sankar.kuna](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sankar.kuna/32/4731_2.png) [@sankar.kuna](https://forum.uipath.com/u/sankar.kuna)\
**Post date:** [March 15, 2017, 9:55am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/9 "2017-03-15T09:55:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikkosinikallio](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mikkosinikallio](https://forum.uipath.com/u/mikkosinikallio)\
**Post date:** [June 7, 2017, 6:17am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/10 "2017-06-07T06:17:40Z")

</div>

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: [c# - How do I split a string on an empty line using .Split()? - Stack Overflow](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!

---

<div class="post-metadata">

**Author:** ![mikkosinikallio](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mikkosinikallio](https://forum.uipath.com/u/mikkosinikallio)\
**Post date:** [June 7, 2017, 6:47am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/11 "2017-06-07T06:47:15Z")

</div>

Actually I got this to work!

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

So, _Environment.NewLine_ works atleast on a .txt file.

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [June 7, 2017, 7:04am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/12 "2017-06-07T07:04:37Z")

</div>

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.

> [@mikkosinikallio](#):
>
> text.Split({“\r\n\r\n”},stringsplitoptions.None)

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

This will also work.

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![mikkosinikallio](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mikkosinikallio](https://forum.uipath.com/u/mikkosinikallio)\
**Post date:** [June 7, 2017, 7:46am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/13 "2017-06-07T07:46:57Z")

</div>

Okay, thank you much!

---

<div class="post-metadata">

**Author:** ![Divyashreem](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/divyashreem/32/464042_2.png) [@Divyashreem](https://forum.uipath.com/u/Divyashreem)\
**Post date:** [June 16, 2017, 10:35am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/14 "2017-06-16T10:35:28Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![arun.arora](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arun.arora/32/405331_2.png) [@arun.arora](https://forum.uipath.com/u/arun.arora)\
**Post date:** [September 28, 2017, 3:37pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/15 "2017-09-28T15:37:54Z")

</div>

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](https://global.discourse-cdn.com/uipath/original/2X/5/58680d63092db072874aee63e54c87e58fa5b5e5.zip) (2.2 KB)

---

<div class="post-metadata">

**Author:** ![octechnologist](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/octechnologist/32/513840_2.png) [@octechnologist](https://forum.uipath.com/u/octechnologist)\
**Post date:** [October 17, 2017, 6:27pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/16 "2017-10-17T18:27:18Z")

</div>

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(" "))**

---

<div class="post-metadata">

**Author:** ![ClaytonM](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/claytonm/32/555957_2.png) [@ClaytonM](https://forum.uipath.com/u/ClaytonM)\
**Post date:** [October 17, 2017, 6:32pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/17 "2017-10-17T18:32:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![octechnologist](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/octechnologist/32/513840_2.png) [@octechnologist](https://forum.uipath.com/u/octechnologist)\
**Post date:** [October 17, 2017, 6:47pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/18 "2017-10-17T18:47:01Z")

</div>

Thanks!

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

![split](https://global.discourse-cdn.com/uipath/original/2X/d/d8e2fed5f873fcff8216942a4892ad4eebd7aa0f.png)

---

<div class="post-metadata">

**Author:** ![Venkatp](https://avatars.discourse-cdn.com/v4/letter/v/9fc29f/32.png) [@Venkatp](https://forum.uipath.com/u/Venkatp)\
**Post date:** [October 24, 2017, 1:16pm UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/19 "2017-10-24T13:16:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Susana](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/susana/32/611_2.png) [@Susana](https://forum.uipath.com/u/Susana)\
**Post date:** [October 25, 2017, 9:49am UTC](https://forum.uipath.com/t/how-to-split-a-string/2098/20 "2017-10-25T09:49:09Z")

</div>

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](https://global.discourse-cdn.com/uipath/original/2X/e/e381371df99196c4403470fbbd5fc0e055d44f96.xaml) (5.9 KB)  
[SplitStringAssign.xaml](https://global.discourse-cdn.com/uipath/original/2X/c/cbf048ae534976edd7462ff5e1a291cd52ab618b.xaml) (6.1 KB)

> [@ClaytonM](#):
>
> 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.

> **[String.Split Method (System)](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?redirectedfrom=MSDN#overloads)**
>
> Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array.

Regards,  
Susana

[Next page](https://forum.uipath.com/t/how-to-split-a-string/2098.md?page=2)
