public static void appendEscapedTextToBuilder(StringBuilder out,String item,char separator){
  for (int i=0; i < item.length(); i++) {
    char ch=item.charAt(i);
    if (ch == '\\' || ch == separator) {
      out.append('\\');
    }
    out.append(ch);
  }
}

public static void appendEscapedTextToBuilder ( StringBuilder out , String item , char separator ) { for ( int i = 0 ; i < item . length ( ) ; i ++ ) { char ch = item . charAt ( i ) ; if ( ch == '\\' || ch == separator ) { out . append ( '\\' ) ; } out . append ( ch ) ; } }
writes chars from item to out , backslash escaping as needed based on separator - - but does not append the seperator itself
