Here you can find the source of sanitize(String string)
static String sanitize(String string)
//package com.java2s; //License from project: Open Source License public class Main { static String sanitize(String string) { string = string.replace(" ", ""); string = string.replace(")(", ")*("); StringBuilder result = new StringBuilder(""); int depth = 0; for (int i = 0; i < string.length(); i++) { if (string.charAt(i) == '-' && depth == 0) { result.append("+(-1)*"); } else { result.append(string.charAt(i)); }/*from w w w. ja v a 2s . c o m*/ if (string.charAt(i) == '(') { depth++; } else if (string.charAt(i) == ')') { depth--; } } return result.toString(); } }