In Java, I have a String variable.
Sometimes the first character of the string is a comma ,
I want to remove the first char only if it is a comma.
What is the best approach to do this?
I would use the ^
anchor together with replaceFirst()
:
niceString = yourString.replaceFirst("^,", "");
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