0

I want to ask question.

I have a dynamic ocr result like "Prosdfad" or "Pro324sd". And so I want to replace the string to be "Protein". I searched on this site but I haven't found it. Is there any turorial?

4
  • Possible duplicate: stackoverflow.com/questions/12734721/… Commented Apr 25, 2014 at 13:36
  • Please be more specific what you want to replace. Only sdfad or something else. Commented Apr 25, 2014 at 13:36
  • so i want to replace "Prosdfad" to "Protein".. all words which contains "Pro" in the beginning will be replaced to protein :) Commented Apr 25, 2014 at 13:40
  • woooow... thank you so muuch @KEYSER and all guys :) Commented Apr 25, 2014 at 13:45

1 Answer 1

1

Something like:

if(str.startsWith("Pro")) {
    str = "Protein";
}

Where str is your String object.

However, note that it's case-sensitive, so this won't match e.g. "prosdfad". And you might want to consider doing a startsWith check further ahead instead of reassigning the String, if the part to be replaced contains some useful information.

Here's the String documentation. It has lots of useful methods such as startsWith, toLowerCase, matches, to name a few.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.