Need help on Split


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…


Try this

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


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!


1 Like


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

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