public static String joinPunctuationMarks(String line){
  String result=line;
  result=result.replace(" ,",",");
  result=result.replace(" ;",";");
  result=result.replace(" :",":");
  result=result.replace(" .",".");
  result=result.replace(" !","!");
  result=result.replace("¡ ","¡");
  result=result.replace(" ?","?");
  result=result.replace("¿ ","¿");
  result=result.replace(" )",")");
  result=result.replace(" ]","]");
  result=result.replace(" }","}");
  result=result.replace("( ","(");
  result=result.replace("[ ","[");
  result=result.replace("{ ","{");
  return result;
}

public static String joinPunctuationMarks ( String line ) { String result = line ; result = result . replace ( " ," , "," ) ; result = result . replace ( " ;" , ";" ) ; result = result . replace ( " :" , ":" ) ; result = result . replace ( " ." , "." ) ; result = result . replace ( " !" , "!" ) ; result = result . replace ( "¡ " , "¡" ) ; result = result . replace ( " ?" , "?" ) ; result = result . replace ( "¿ " , "¿" ) ; result = result . replace ( " )" , ")" ) ; result = result . replace ( " ]" , "]" ) ; result = result . replace ( " }" , "}" ) ; result = result . replace ( "( " , "(" ) ; result = result . replace ( "[ " , "[" ) ; result = result . replace ( "{ " , "{" ) ; return result ; }
scanning from left - to - right , a comma or period preceded by a space will become just the comma / period .
