0

I need to make a program that returns an error list in a file.

The problem I'm having is that it returns the String in one big line, with the following toString method:

 @Override
    public String toString() {
        return "Resultat{" +
                "status=" + complet + "\n" + ", erreur=" + erreur +
                '}';
    }

Is there a way to get a return of the specific String in restricted length of 80 length, then skip line?

For exemple:

Apple
Green

instead of(of course the line would be considerably longer in that case).

Apple Green
MaelPJ
  • 11
  • 1

1 Answers1

1

You can do this with regex, capturing groups of 80 characters, (.{80}) and replacing them with the captured group followed by a newline $1\n.

Something like:

@Override
public String toString() {
    final String oldString = "...";
    // TODO - build old toString here...
    return oldString.replaceAll("(.{80})", "$1\n");
}

Not saying this is a fast way (and it sounds like something whatever you're formatting the String for should handle, not the toString method itself...), but it should do the trick.

BeUndead
  • 3,463
  • 2
  • 17
  • 21