Need help on Split

Hi,

I have an requirment,
eg: Input is : Sharan - Level and required output is Sharan, Input is : Sharan - basava - Level and required output is Sharan - basava.

I have tried using split function, but I am getting Sharan as output in first and in second I am not able to achieve Sharan - basava.

Can some one help me…

@Sharanabasava1

Try this

Str.Replace(" - Level","")

Cheers

Hi @Sharanabasava1,

Heed on @Anil_G 's advice to replace the “- Level” with “” instead of Splitting the string.

Also, add .Trim to make sure that there are no white spaces left.

Str.Replace(“- Level”,“”).Trim

Happy automation!

Kenneth

1 Like

HI,

FYI, another approach : if you need to split the last " - " without specific keyword, the following will work.

yourString.Substring(0,yourString.LastIndexOf(" - "))

image

Regards,