Consider the below String
String names = "Bharath-Vinayak-Harish-Punith"
I want to get output in the form of string it contains only Bharath. (String up to the first occurrence of "-" operator). Anyone can please tell me, how can be we do this?
You could use split:
def theName = names.split(/-/)[0]
split returns a String array, then get the first array element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With