private static String csvFormat(String s){
  if (s.contains("\"") || s.contains("\n") || s.contains(",")) {
    return "\"" + s.replace("\"","\"\"") + "\"";
  }
  return s;
}

private static String csvFormat ( String s ) { if ( s . contains ( "\"" ) || s . contains ( "\n" ) || s . contains ( "," ) ) { return "\"" + s . replace ( "\"" , "\"\"" ) + "\"" ; } return s ; }
formats a string and returns it so that it can be inserted into a csv file without disrupting the formatting of the file and the string . specifically , quotation marks are added around the string if it contains new - line characters , commas , or quotation marks . each quotation mark inside the string is also replaced with two quotation marks .
