0

One more question :-)

I have a string which looks like this:


Saved
Saved
Saved
->12345678
Saved
Saved
->98765432

And I need to replace all the ->XXXXXXXX Strings to the CORRUPTED. The numbers after -> are different. How I can do te trick?

Excuse for my English.

1 Answer 1

1

String.replaceAll() is your friend:

String out = in.replaceAll("^\\-\\>\\d+$", "CORRUPTED");

This replaces everything of the form ->[numberHere] with "CORRUPTED", using Regular Expressions:

  • ^ matches the start of a line.
  • $ matches the end of the line.
  • \d+ matches a number of 1 or more digits.

Rubular demo here.

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.