I’m looking for a way to remove the comma and all that comes after it in a string, for example:
important, not so important
I’d like to remove “,not so important”
Any ideas? Thanks in advance!
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.
You can do it with
substringandindexOf:but you’d have to be sure that a comma is in there (test it before).
Another possibility is to use
split():this works even without testing beforehand but might perform unnecessary string operations (which is probably negligible on small strings).