问题
I have a simple treatement but I'm stuck
I have something like
"\"iVBORw0KGgoAAAANSUhEUgAAAwoAAADwCAYAAACg2ZPDAAAABHNCSVQICAgIfAhkiAAAIABJREFU\\neJzt3XecXVW99";
public static void main(String[] args) {
String value = "\"iVBORw0KGgoAAAANSUhEUgAAAwoAAADwCAYAAACg2ZPDAAAABHNCSVQICAgIfAhkiAAAIABJREFU\\neJzt3XecXVW99";
String filtre1 = value.replaceAll("\"", "");
String filtre2 = filtre1.replaceAll("\\n", "");
System.out.println(filtre2);
}
the result is .. I have always "\n" I want to remove it
iVBORw0KGgoAAAANSUhEUgAAAwoAAADwCAYAAACg2ZPDAAAABHNCSVQICAgIfAhkiAAAIABJREFU\neJzt3XecXVW99
回答1:
Maybe:
String filtre2 = filtre1.replaceAll("\\n", "");
need to be :
String filtre2 = filtre1.replaceAll("\\\\n", "");
(sorry i cannot just add comment)
回答2:
You could try this:
public static void main(String[] args) {
String value = "\"iVBORw0KGgoAAAANSUhEUgAAAwoAAADwCAYAAACg2ZPDAAAABHNCSVQICAgIfAhkiAAAIABJREFU\\neJzt3XecXVW99";
String filtre1 = value.replaceAll("\"", "");
String filtre2 = filtre1.replaceAll("\\\\n", "");
System.out.println(filtre2);
}
回答3:
You basically have two choices, both of which are in the below code:
public static void main(String[] args) {
String value = "\"iVBORw0KGgoAAAANSUhEUgAAAwoAAADwCAYAAACg2ZPDAAAABHNCSVQICAgIfAhkiAAAIABJREFU\\neJzt3XecXVW99";
System.out.println(value.replace("\"", "").replace("\\n", ""));
System.out.println(value.replaceAll("\"|\\\\n", ""));
}
来源:https://stackoverflow.com/questions/49565658/replaceall-java-method-to-remove-n-from-string