# Split a string variable

**URL:** <https://forum.uipath.com/t/split-a-string-variable/762460>\
**Category:** Studio\
**Tags:** system, activities\
**Created:** [August 26, 2024, 3:32pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460 "2024-08-26T15:32:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_Martinez](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@Rodrigo\_Martinez](https://forum.uipath.com/u/Rodrigo_Martinez)\
**Post date:** [August 26, 2024, 3:32pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/1 "2024-08-26T15:32:04Z")

</div>

Hi everyone.

I’m working in an automation which has a variable called ID.

That ID is written this way: prefix, “-”, IDNumber, “-”, VerificationNumber.

I want to split that text in order to get the prefix on one hand and the IDNumber + VerificationNumber on the other.

I’ve tried ID.Split(“-”)(1) and it didn’t work out.

Appreciate your help.

Regards,

---

<div class="post-metadata">

**Author:** ![vrdabberu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vrdabberu/32/484365_2.png) [@vrdabberu](https://forum.uipath.com/u/vrdabberu)\
**Post date:** [August 26, 2024, 3:36pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/2 "2024-08-26T15:36:26Z")

</div>

Hi @Rodrigo_Martinez

Can you give an sample input and required Output.

Regards

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Martinez](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@Rodrigo\_Martinez](https://forum.uipath.com/u/Rodrigo_Martinez)\
**Post date:** [August 26, 2024, 3:50pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/4 "2024-08-26T15:50:23Z")

</div>

Hi Varunraj.

The input can be:  
1-1234567-8  
2-9876543-1  
24-6543210-9

The expected output is:

|Prefix| ID | Verification Number

|1 | 1234567 | 8 |  
|2 | 9876543 | 2 |  
|24 | 6543210 | 9 |

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [August 26, 2024, 3:56pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/5 "2024-08-26T15:56:46Z")

</div>

@Rodrigo_Martinez,

Use this in assign activity strArray would be string array datatype variable.

`strArry=StrInput.Split("-")`

From this array you can get values by index like I’d can be extracted by

`Id=strArray(1)`

Prefix

`prefix=strArray(0)`

Verification Number

`varNo=strArray(2)`

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Parvathy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/parvathy/32/484539_2.png) [@Parvathy](https://forum.uipath.com/u/Parvathy)\
**Post date:** [August 26, 2024, 3:57pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/6 "2024-08-26T15:57:46Z")

</div>

(post deleted by author)

---

<div class="post-metadata">

**Author:** ![vrdabberu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vrdabberu/32/484365_2.png) [@vrdabberu](https://forum.uipath.com/u/vrdabberu)\
**Post date:** [August 26, 2024, 3:58pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/7 "2024-08-26T15:58:12Z")

</div>

Hi @Rodrigo_Martinez

Check the below syntax then:

```auto
Assign Activity -> Input = "1-1234567-8"
Assign Activity -> parts = Input.Split("-"c)
Assign Activity -> Prefix = parts(0)
Assign Activity -> ID = parts(1)
Assign Activity -> VerificationNumber = parts(2)

```

**FLOW:**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/5/1/d/51d7ba45854b12064f064a8516243ec23ef9278a.png)

**VARIABLE DATATYPE:**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/7/d/77ddba5b3046056d960914318951aa1b37adde10.png)

**OUTPUT:**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/4/9/c/49c59203d243ccbe45c09562044d349cf531b4cd.png)

Regards

---

<div class="post-metadata">

**Author:** ![postwick](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/postwick/32/227083_2.png) [@postwick](https://forum.uipath.com/u/postwick)\
**Post date:** [August 26, 2024, 4:00pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/8 "2024-08-26T16:00:06Z")

</div>

The resulting array is 0 index, so getting the element with index 1 is the second element IDNumber and the first element is index 0 prefix.

---

<div class="post-metadata">

**Author:** ![adiijaiin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/adiijaiin/32/523523_2.png) [@adiijaiin](https://forum.uipath.com/u/adiijaiin)\
**Post date:** [August 26, 2024, 5:01pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/9 "2024-08-26T17:01:20Z")

</div>

Hi @Rodrigo_Martinez

Welcome to the Community!

You can split it using

> yourVariable.Split(“-”,2)

It will split your data in 2 tokens by using hyphen(-) as delimeter.

Screenshot for reference. My variable name is Name.

![This image shows a debugging session in a programming environment where a string variable named 'Name' with the value "SomePrefix-108298892-9191" is being split into an array using the "." delimiter. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/4/9/b/49b4034005923f00d0085dea14772a0e32788c49.png)  
e

Happy Automation! 😃

---

<div class="post-metadata">

**Author:** ![adiijaiin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/adiijaiin/32/523523_2.png) [@adiijaiin](https://forum.uipath.com/u/adiijaiin)\
**Post date:** [August 26, 2024, 5:06pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/10 "2024-08-26T17:06:06Z")

</div>

Hi @Rodrigo_Martinez

And if you’re trying to generate a DataTable based on

> [@Rodrigo\_Martinez](#):
>
> 1-1234567-8  
> 2-9876543-1  
> 24-6543210-9

Then Use Generate DataTable Activity with **“-”** as Column Separators and **Newline** as Newline separators.

 ![The image shows the "Generate Data Table Wizard" interface with sample input data, table options, data formatting options, and a test preview of the generated data table. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/d/9/0/d9088b01078e84263b065e0d09a0284faecd8b77.png)

Thanks  
Happy Automation! 😃

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Martinez](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@Rodrigo\_Martinez](https://forum.uipath.com/u/Rodrigo_Martinez)\
**Post date:** [August 27, 2024, 3:02pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/11 "2024-08-27T15:02:58Z")

</div>

Hi everyone.

Thank you all for your help.

I forgot to mention that i was working with C#.

I had to use an assign activity like this:

Prefix: ID.Split(‘-’ , System.StringSplitOptions.None)[0]  
IDNumber: ID.Split(‘-’ , System.StringSplitOptions.None)[1]  
VerificationNumber: ID.Split(‘-’ , System.StringSplitOptions.None)[2]

Now it’s a happy automation indeed.

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [August 30, 2024, 3:04pm UTC](https://forum.uipath.com/t/split-a-string-variable/762460/12 "2024-08-30T15:04:00Z")

</div>

Closed on August 30, 2024, 3:04pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
