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

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

Thanks in advance

  1. Split your text by β€œ-”
    image

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

Hi @smrutismita.samal ,

System.Text.RegularExpression.Regex.Matches(extractedText,β€œ\d{8}.*$”)(0).Value

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?

image

Hi @smrutismita.samal, welcome to the Community.

Try this:

stringData.Split("-"c)(5).ToString

Output:

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

@smrutismita.samal

In that case, can you try this RegEx:

-(\d+)-\w+-(\d+)-\w+

image

Best Regards.

Since numbers are 8 digit always,

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

System.Text.RegularExpression.Regex.Matches(extractedText,β€œ\d{8}.*$”)(0).Value

Hi,

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

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=-)\d{8}(?=-)").Value

Regards,

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.