How to find the string values from a variable in another?

Hello all,

I want to compare the - value present inside the string variable with the another string variable.
These values are dynamic.
2 string variables
Vessel1 = NYK JOANNA 128S (NJOT)
Comp_val= ‘NYK JOANNA 128S’ Arrival at Transhipment Port
NYK JOANNA 128S

So i have written the code as below
using one more variable
Comp_Vessel1=Split( Vessel1.ToString,"(")(0).ToString

image

Thank you
Seema

@Seema_S
on a first look some splits / replacements from your code have risk to block the compair

my understanding of your requirement
LongString: NYK JOANNA 128S (NJOT)
SearchString: ‘NYK JOANNA 128S

So a simple LongString.Contains(SearchString) should work

2 Likes

@ppr
I had tried.
It dint work

u can try it and check with the strings i have given…

@Seema_S

First of all my understanding of your requirements is correct?
Have a look here
grafik

I hope you have done the compair on strings and not on splits or tokens with removed spaces

2 Likes

@ppr

see i have

Vessel1 = NYK JOANNA 128S (NJOT)
Comp_val = ‘NYK JOANNA 128S’ Arrival at Transhipment Port
NYK JOANNA 128S

so u can consider the Vessel1 =Searchstring
Comp_val = longstring.

Well in the longsring there is no - (NJOT)

@Seema_S

NYK JOANNA 128S (NJOT) is only partly contained in ‘NYK JOANNA 128S’ Arrival at Transhipment Port
NYK JOANNA 128S with NYK JOANNA 128S

so LongString.Contains(SearchString) is False and this is correct

But now lets define when it it rated as found. When should it be rated as found: Total match, 75% match…

1 Like

i want to find the - NYK JOANNA 128S
in the - Comp_val…

So i have done the split string - Comp_Vessel1 =Split( Vessel1.ToString,"(")(0).ToString

In the beginning i only i have sent it. Please go thouh it again

Vessel1 = NYK JOANNA 128S (NJOT)
Comp_va l= ‘NYK JOANNA 128S’ Arrival at Transhipment Port
NYK JOANNA 128S

So i have written the code as below
using one more variable
Comp_Vessel1 =Split( Vessel1.ToString,"(")(0).ToString

Comp_va l.contains( Comp_Vessel1)

@Seema_S
Looking to your feedback, could define a requirement like

From NYK JOANNA 128S (NJOT)
Use text without text in () = NYK JOANNA 128S = SearchString
And Look for LongString.Contains(SearchString)

grafik

I was using your split logic for extracting text without text in (). Removing the last space with the trim changed the result of contains from false to true

2 Likes

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