Remove the all the text after second (-) character from a string

String - 235-65-r17-108-h-26093672-pn
Need Result- 26093672

Thanks in advance

  1. Split your text by β€œ-”

  2. Join last two elements of the array by β€œ-”

Hi @smrutismita.samal ,


You can try this.

1 Like

Thanks for your response.
Split your text by β€œ-” : This returns System.String

It returns an Array of Strings. That allows you to combine the last two members of the array into the result that you want. What’s your question specifically?


Hi @smrutismita.samal, welcome to the Community.

Try this:



Hope this helps,
Best Regards.

How to check split value from -System.String
I have dynamic string value -
eg- -108-h-20093972-pn
eg- -1095-p-20393972-pn
eg- -82-v-29866091-pn

I want Result like below -
1 . 20093972
2. 20393972
3. 29866091


In that case, can you try this RegEx:



Best Regards.

Since numbers are 8 digit always,

This will work : β€œ\d{8}.*$”



If you want to extract 8 digit value, the following will work.



1 Like

Oh, you edited your original requirement. So you no longer require β€œ-pn”, just the numbers right before?

In that case your result is simply MyArray(MyArray.Count-2) which is just taking the 2nd last element from the array.

Hi @smrutismita.samal

Sure, here’s an example UiPath workflow to extract the result β€œ26093672” from the given string β€œ235-65-r17-108-h-26093672-pn”:

  1. Use the Assign activity to assign the string to a variable:
  • Variable: inputString

Value: 235-65-r17-108-h-26093672-pn

  1. Use the Assign activity to extract the result from the string using the Split method and array indexing:
  • Variable: result
  • Value: inputString.Split("-"c)(^2)
  1. Use the Write Line activity to display the result:
  • Text: result

Thanks Its working fine.

1 Like

thanks for your response

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