How to get data from a line of string

Hi,

I am having the following line of strings

NAT_NAT_ELA_MOB_DSP_LOY_RET_P2+++_NON_Autotrader_ATC-ELA-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50_OPX_DFV_NON_N_Learn More_N_NON

from the above string I want to pick only OPX value, I will be having dyanmic values during each refresh, so the line to have OPX value, how can I pick that value alone?

1β€”> NAT_NAT_HYU_MOB_DSP_LOY_RET_P2+++_PGD_Autotrader_ATC-HYU-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50_None_DFV_NON_N_Learn More_N_NON

2----> NAT_NAT_HYU_MOB_DSP_LOY_RET_P2+++Autotrader_ATC-HYU-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50**PMP**DFV_NON_N_Learn More_N_NON

Now, in this above two lines I want to get the word next to PGD and PMP, so in the above example i want to get the values as Autotrader for the lone 1 and DFV for the line 2. How can i get?

1 Like

Hi @monish06,

May I have some more clarifications, like what value(s) are you wanting to fetch?

Thanks & Regards,
Apurba

@monish06 Will the Underscores be there always in it?

From this string

1-----> NAT_NAT_ELA_MOB_DSP_LOY_RET_P2+++_NON_Autotrader_ATC-ELA-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50_OPX_DFV_NON_N_Learn More_N_NON

I want to check if the line contains β€œOPX”

2β€”> NAT_NAT_HYU_MOB_DSP_LOY_RET_P2+++_PGD_Autotrader_ATC-HYU-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50_None_DFV_NON_N_Learn More_N_NON

From the 2nd line of string I want to get the words next to the word of β€œPGD” so, in this line I want to get the word β€œAutorader”.

3----> NAT_NAT_HYU_MOB_DSP_LOY_RET_P2+++Autotrader_ATC-HYU-MOB-RET-Used/CPO-SRP-Mobile-320x50_320x50_PMP_DFV_NON_N_Learn More_N_NON

From the 3rd line of string I want to get the words next to the word of β€œPMP” so, in this line I want to get the word β€œDFV”.

Note: these string will change dynamically.

@monish06 What is meant by Dynamic Change? :sweat_smile:

@monish06

Please try to use Regex patterns something like:

image

and see if that helps

1 Like

Hi @monish06,

  1. For checking OPX is there or not, please use the below syntax -
    YourString.ToString.Trim.ToUpper.Contains(β€œOPX”)

  2. For getting the next word after PGD, please use the below Regex Syntax -
    System.Text.RegularExpressions.Regex.Match(YourString,"(?<=PGD_)[A-Za-
    z]+(?=_)").ToString.Trim

  3. For getting the next word after PMP, please use the below Regex Syntax -
    System.Text.RegularExpressions.Regex.Match(YourString,"(?<=PMP_)[A-Za-
    z]+(?=_)").ToString.Trim

If you want to fetch the word after PGD or PMP dynamically then, please use the below syntax -
System.Text.RegularExpressions.Regex.Match(YourString,"(?<=(PGD|PMP))[A-Za-
z]+(?=
)").ToString.Trim

Thanks & Regards,
Apurba

2 Likes

Thank you for the solution @apurba2samanta

1 Like

Hi @monish06,

Always most welcome. :slightly_smiling_face:

Thanks & Regards,
Apurba

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