I want to get the last word by splitting

Hi

Input: GEMSAM_OU_CLP_GEMS_CHL

How to get the output mentioned below from the above string

output:

CHL

Thanks
Likitha

StrText=“GEMSAM_OU_CLP_GEMS_CHL”

You can trh this … It will give you CHL

StrText.Split("_"c).Last

for reference you can see the output: -

@vinjam_likitha

you can try this regex expression also

strText = “GEMSAM_OU_CLP_GEMS_CHL”

System.Text.RegularExpressions.Regex.Split(strText,“_”).Last

output
image

let me its working or not for you
@vinjam_likitha

Hi @vinjam_likitha

Input="GEMSAM_OU_CLP_GEMS_CHL"
Output=Input.Split("_"c).Last

Hope it helps

You can use string split functions…

yourinput.Split("_"c).Last

Try this-

Assign:
- InputString = “GEMSAM_OU_CLP_GEMS_CHL”
- OutputString = InputString.Split("_"c).Last()

Thanks!!

Hi,

you can use below expression:

System.Text.RegularExpressions.Regex.Match(Input, “([^_]+)$”).Value

Explanation:

  • The regular expression "([^_]+)$" is used to match the last sequence of characters that doesn’t contain underscores in the input string.
  • Match(Input, "([^_]+)$") finds the last match in the input string, and Value extracts that match.

1st Assign variable
StrText= “GEMSAM_OU_CLP_GEMS_CHL”
2nd use substring
StrText.Substring(StrText.LastIndexOf(‘_’)+1)

Note I am useing c# langauage

Hi @vinjam_likitha

You can use the Data manipulation and Regular expression for this.
Data Manipulation -

- Assign -> Input = "GEMSAM_OU_CLP_GEMS_CHL"
- Assign -> Output = Input.Split("_").Last

Regular expressions -

- Assign -> "GEMSAM_OU_CLP_GEMS_CHL"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“((?<=\_)[A-Z]+$)”).Value

image

Hope it helps!!