Is there a way to use str.charAt(index) to replace a specific char by index?
Something like this:
str.setCharAt(1,'X'); // replace 2nd char with 'X'
Is there any easy way to do that?
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.
Depending on the source of
stryou may be able to do something like this:If you have a string that you are piecing together and modifying a lot, it makes more sense to use a
StringBuilderinstead of a string. However, if you are modifying aStringfrom another method call, the other answers may be more appropriate.