Skip to content

Instantly share code, notes, and snippets.

@cmoore4
Created February 24, 2013 20:12
Show Gist options
  • Save cmoore4/5025392 to your computer and use it in GitHub Desktop.
Save cmoore4/5025392 to your computer and use it in GitHub Desktop.
Simple CSV generator in Scala.
def makeCSV(csvValues: List[String]) = {
csvValues.map(s => "\""+s.replace("\"", "\\\"").replace(",", "\\,")+"\"").mkString(",") + "\n";
}
val csv = List(
List("a", "b", "c", "d"),
List("e", "f", "g", "h"),
List("i", "j", "k", "l")
);
csv.foreach(s => print(makeCSV(s)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment