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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the general case, I agree with the
splitmethod in the previous answer, but, when only returning the first string, the substring method is the same amount of work for the programmer (and, for insanely large strings, less computational work):