My method successfully takes a binary expression tree and turns it into prefix, postfix, and infix notation. However, due to the accuracy of the final string, it must be exactly equal.
So before I return my output, I will run a method to quickly edit that output to remove any flaws.
(* (+ 8 4) (- 7 (/ 6 3))) ===> (*(+ 8 4)(- 7(/ 6 3)))
((8 4 +) (7 (6 3 /) -) ) =====> ((8 4 +)(7 (6 3 /)-))
What needs to be changed, are the spacing inbetween parens. My goal was to find all cases of a string, remove them, and reinput in the string without spaces.
underlines are extra spaces (*(+ 8 4)(- 7_(/ 6 3)))
My code was supposted to be String.split(") (");
but error signs... unmatched closing ')')(???
public String antibullshiter(String out) {
out = out.replaceFirst(") (", "X"); //edited
String[] parts = out.split("X");
String part1 = parts[0];
String part2 = parts[1];
part1 = part1 + ")";
part2 = part2 + "(";
out = part1 + part2;
return out;}
How do I harness the power of String.split()?
edit: thanks guys, but I realized I just had to deal with the primary method in itself
split()
does no use plain strings to split on – vandale Nov 27 '13 at 4:40