Looking for this type of String Function / How to?

Hi guys I’m looking for how to do this in Uipath. If we had the following text on a clipboard how do I:

  1. Extract all the text after ‘ONEONE’ and assign it to a new variable?
  2. Extract all the text before ‘TWOTWO’ and assign it to a new variable?
  3. Extract all the text between ‘ONEONE’ and ‘TWOTWO’ and assign it to a new variable?

DataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataONEONEDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataTWOTWODataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataDataData

Hi,

The following might help you.

First, use Get From Clipboard Activity and assign the value to str variable(say strData).

  1. Extract all the text after ‘ONEONE’ and assign it to a new variable?

strNew = System.Text.RegularExpressions.Regex.Match(strData,"(?<=ONEONE).*")

  1. Extract all the text before ‘TWOTWO’ and assign it to a new variable?

strNew = System.Text.RegularExpressions.Regex.Match(strData,".*(?=TWOTWO)")

  1. Extract all the text between ‘ONEONE’ and ‘TWOTWO’ and assign it to a new variable?

strNew = System.Text.RegularExpressions.Regex.Match(strData,"(?<=ONEONE).*(?=TWOTWO)")

If your data contains line break and you want to include it in the result, please replace .* to [\s\S]*

Regards,

1 Like

Hi, there’s another way that using Split method:

  1. Extract all the text after ‘ONEONE’ and assign it to a new variable?
    strVar = strData.Split({“ONEONE”}, StringSplitOptions.None).Last.toString
  2. Extract all the text before ‘TWOTWO’ and assign it to a new variable?
    strVar = strData.Split({“TWOTWO”}, StringSplitOptions.None).First.toString
  3. Extract all the text between ‘ONEONE’ and ‘TWOTWO’ and assign it to a new variable?
    strVar = strData.Split({“ONEONE”,“TWOTWO”}, StringSplitOptions.None)(1).toString

Hi @tranthao240495 I’m looking at your answer for 1 and 2; won’t 2 give the same result as 1 in taking the text after ‘TWOTWO’ rather than before ‘TWOTWO’ or am I reading that incorrectly? Just wanted to make sure it was not a typo, thanks.

Sorry, typing mistake. The right answer would be:
2. Extract all the text before ‘TWOTWO’ and assign it to a new variable?
strVar = strData.Split({“TWOTWO”}, StringSplitOptions.None).First.toString

Ok thanks, yea thought it might be. And are the string functions essentially just written in javascript?

No, just in Assign activity, variable name in “To” and string function in “Value”

Hey @tranthao240495 one more related question, how would I do these with the following set of text on the clipboard, similar concept just slightly different:

  1. Extract text between the first instance of ‘ONEONE’ and the second instance of ‘TWOTWO’?
  2. Extract the text between the second instance of ‘ONEONE’ and the second instance of ‘TWOTWO’?

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaONEONEaaaaaaaaaaaaaaaaaaaaaaaTWOTWOaaaaaaaaaaaaaaaaaaaaaaaaaONEONEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTWOTWOaaaaaaaaaa

Please try this

  1. String.Join(“TWOTWO”,split(strData,“TWOTWO”).ToArray.ToList.GetRange(0,2)).Substring(strData.IndexOf(“ONEONE”)+“ONEONE”.Length)
  2. String.Join(“TWOTWO”,split(strData,“TWOTWO”).ToArray.ToList.GetRange(0,2)).Substring(String.Join(“ONEONE”,split(strData,“ONEONE”).ToArray.ToList.GetRange(0,2)).Length+“ONEONE”.Length)