For examples, I have:
String s = "{\"ABC\"}:Mycontent{\"123\"}";
I only want to get the Mycontent{“123”} part and this part can be changed dynamically. Can anybody please show me how to do it (Fast performance)?
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.
Split method inside string can split a string around matches of regular expression so you can use this method.
You can also use subsequence method if the position of the string you want is always the same.
Also you can use the substring method.
Many ways. Personal favorite is substring
I put [] around end because it is not necessary. If you do not put an end index the substring will continue until the end of the string. Both indexes must be integers. Also this method returns a string.
If the size of the number changes dynamically aswell (e.g. 123 turns to 4567) you can solve this by not using an end index then using a find function and finding the character that comes after the last digit in your string (I suppose this does not change) and then replacing that character (using a replace method) with a \0 so the string ends there.
All the methods I have mentioned and there explanations can be found in javadoc