Possible Duplicate:
String Functions how to count delimiter in string line
I have a string as str = “one$two$three$four!five@six$” now how to count Total number of “$” in that string using java code.
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.
Using replaceAll:
Prints:
Using replace instead of replaceAll would be less resource intensive. I just showed it to you with replaceAll because it can search for regex patterns, and that’s what I use it for the most.
Note: using replaceAll I need to escape $, but with replace there is no such need: