# Assign Activity - Splitting Strings

**URL:** <https://forum.uipath.com/t/assign-activity-splitting-strings/358612>\
**Category:** Help\
**Tags:** web, activities, system\
**Created:** [November 4, 2021, 1:39pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612 "2021-11-04T13:39:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 4, 2021, 1:39pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/1 "2021-11-04T13:39:29Z")

</div>

Hello everyone!

I have this kind of string and I can’t get it to split how i want it.  
“ID: 12345 Name: Firstname Lastname Position: Assistant”

I tried splitting it with Employee.Split(":"c) but than I get:

```auto
ID
 12345 Name
 Firstname Lastname Position
 Assistant

```

Instead of this:

```auto
12345 
Firstname Lastname 
Assistant

```

Is there a way to split a String at two positions at once?  
for Example, to get the ID, i would need to split at “ID: " and " Name: \*”

Thanks alot, Mahrie 🐻

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [November 4, 2021, 1:45pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/2 "2021-11-04T13:45:51Z")

</div>

Hi

Fine in that case we can use REGEX method instead of split method  
Like this

For I’d value mention like this in assign activity

str\_Id = System.Text.RegularExpressions.Regex.Match(Strinput.ToString,”(?\<=Name:).\*(?=Position:)”).ToString.Trim

For Name

str\_Name = System.Text.RegularExpressions.Regex.Match(Strinput.ToString,”(?\<=NAME:).\*(?=NAME:)”).ToString.Trim

For Postion

str\_position = System.Text.RegularExpressions.Regex.Match(Strinput.ToString,”(?\<=Position:).\*”).ToString.Trim

If you have multiple values then use MATCHES instead of MATCH

Cheers @mahrie

---

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 4, 2021, 1:49pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/3 "2021-11-04T13:49:05Z")

</div>

Can you explain what all that in the brackets means?  
System.Text.RegularExpressions.Regex.Match(Strinput.ToString,**”(?\<Name:).\*(?=Position:)”**).ToString.Trim

What does it do? For example “?\<”

Mahrie 🐻

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [November 4, 2021, 1:50pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/4 "2021-11-04T13:50:27Z")

</div>

> [@mahrie](#):
>
> What does it do? For example “?\<”

It’s a typo from my side

Actually it is ?\<=

It means if we know the position of one word or two words then we can get the word in between them

To denote in between them we use ?\<= and ?=

Cheers @mahrie

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [November 4, 2021, 2:15pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/5 "2021-11-04T14:15:46Z")

</div>

Hi,

Another solution :  
If there are multiple records in your string, the following might be better.

 ![img20211104-b](https://global.discourse-cdn.com/uipath/original/4X/1/1/f/11f5898dee8c1c7bb21787c9dfb1d4652643aca7.png)

```
mc = System.Text.RegularExpressions.Regex.Matches(yourString,"ID:\s*(?<ID>\w+)\s+Name:\s*(?<Name>\S+\s+\S+)\s+Position:\s*(?<Position>.*)")

```

[Sample20211104-6.zip](https://forum.uipath.com/uploads/short-url/rLZ3cf8fajhtUYN27nItRxGRNaw.zip) (2.5 KB)

Regards,

---

<div class="post-metadata">

**Author:** ![artur.stepniak](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/artur.stepniak/32/259302_2.png) [@artur.stepniak](https://forum.uipath.com/u/artur.stepniak)\
**Post date:** [November 4, 2021, 2:26pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/6 "2021-11-04T14:26:10Z")

</div>

Hello,

you can easily remove both “ID” and “Position” label. So you can firstly split a string as you’ve mentioned and then remove “ID” and “Position” string from the list that you’ve created. List.Remove() method should get the work done.

Best,

Artur

---

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 4, 2021, 2:26pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/7 "2021-11-04T14:26:55Z")

</div>

> [@Palaniyappan](#):
>
> System.Text.RegularExpressions.Regex.Match(Strinput.ToString,”(?\<=Name:).\*(?=Position:)”).ToString.Trim

If i do that, the variable just stays empty. Could it be there is another typo, not just the ?\<= that you fixed on your post?

---

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 4, 2021, 2:31pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/8 "2021-11-04T14:31:47Z")

</div>

Thats seems really complex. Could you explain the what the code does?

---

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 4, 2021, 2:32pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/9 "2021-11-04T14:32:23Z")

</div>

I will try this in case the RegEx Version wont work, because now I kind of want to make it work.

---

<div class="post-metadata">

**Author:** ![artur.stepniak](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/artur.stepniak/32/259302_2.png) [@artur.stepniak](https://forum.uipath.com/u/artur.stepniak)\
**Post date:** [November 4, 2021, 2:34pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/10 "2021-11-04T14:34:17Z")

</div>

Not sure if REGEX is really necessary in that case. 🙂 If you’d like to stick with it, there’s a simpler method to use it - “Matches” activity. It does the same as the code showed by colleagues.

Best,

Artur

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [November 4, 2021, 2:50pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/11 "2021-11-04T14:50:54Z")

</div>

Hi,

```
"ID:\s*(?<ID>\w+)\s+Name:\s*(?<Name>\S+\s+\S+)\s+Position:\s*(?<Position>.*)"

```

First, \s\* or \s+ means 0 (or 1) or more whitespace. For now, replace it to " " to understand easily.

```
"ID: (?<ID>\w+) Name: (?<Name>\S+ \S+) Position: (?<Position>.*)"

```

Next `(?<xxx>expression)` means named group. We can get it by name as m.Group(“ID”).  
To understand easier, use simple group.

```
"ID: (\w+) Name: (\S+ \S+) Position: (.*)"

```

\w+ means 1 or more word characters.  
\S+ means 1 or more non-whitespaces.

So the above expression matches the following.

“ID: ( **1 or more word characters** ) Name: ( **1 or more non-whitespaces 1 or more non-whitespaces** ) Position: ( **0 or more any characters** )”

Finally we can get characters inside parentheses by name like m.Group(“ID”).Value

Regards,

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [November 4, 2021, 3:01pm UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/12 "2021-11-04T15:01:07Z")

</div>

> [@mahrie](#):
>
> If i do that, the variable just stays empty. Could it be there is another typo, not just the ?\<= that you fixed on your post?

It worked for me

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/8/c/68c1297fef0ceae63e7a2cd1d603296450b5e3e3.jpeg)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/c/d/7cdab2bdfdb2ade326411106676e7dd4bd648e27.jpeg)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/3/c/4/3c40e7806a1b7071cdf645d3ad9026f879cfdda8.jpeg)

Cheers @mahrie

---

<div class="post-metadata">

**Author:** ![mahrie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahrie/32/176976_2.png) [@mahrie](https://forum.uipath.com/u/mahrie)\
**Post date:** [November 5, 2021, 8:30am UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/13 "2021-11-05T08:30:22Z")

</div>

> [@artur.stepniak](#):
>
> you can easily remove both “ID” and “Position” label. So you can firstly split a string as you’ve mentioned and then remove “ID” and “Position” string from the list that you’ve created. List.Remove() method should get the work done.

I kept this in mind and tried it. Wasn’t exactly the solution, but I just used .replace() instead of remove, which than worked out for my case.

Thanks everyone,  
Mahrie 🐻

---

<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:** [November 8, 2021, 8:30am UTC](https://forum.uipath.com/t/assign-activity-splitting-strings/358612/14 "2021-11-08T08:30:40Z")

</div>

Closed on November 8, 2021, 8:30am UTC

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