Problem:
If String ends with \ r, remove \ r
I started with something like this
if (masterValue.endsWith(CARRIAGE_RETURN_STR)) {
masterValue = masterValue.replace(CARRIAGE_RETURN_STR, "");
}
Where
public static final String CARRIAGE_RETURN_STR = (Character.toString(Constants.CARRIAGE_RETURN));
public static final char CARRIAGE_RETURN = '\r';
It seems uncomfortable to me.
Is there an easy way to just remove the \ r character?
Then I went to the following:
if (value.contains(CARRIAGE_RETURN_STR)) {
value = value.substring(0, value.length()-3);
// - 3, since we start with 0 (1), end with the end with \ n (2), and we need to remove 1 char (3)
But this also seems uncomfortable.
Can you offer a lighter, more elegant solution?
source
share