Convert comma separated text to new line

You can use the replace() function in most programming languages to convert a comma-separated text to a new line. Here are a few examples:

JavaScript

const text = "apple,banana,orange";
const newText = text.replace(/,/g, "\n");
console.log(newText);
// Output:
// apple
// banana
// orange

Python

text = "apple,banana,orange"
new_text = text.replace(",", "\n")
print(new_text)
# Output:
# apple
# banana
# orange

Java

String text = "apple,banana,orange";
String newText = text.replace(",", "\n");
System.out.println(newText);
// Output:
// apple
// banana
// orange

Bash

text="apple,banana,orange"
new_text=${text//,/\\n}
echo "$new_text"
# Output:
# apple
# banana
# orange

These examples replace each comma (,) with a new line (\n) using regular expressions. The g flag at the end of the regular expression makes the replacement global, so all commas are replaced, not just the first one.

You can also use the split() function to achieve the same result:

const text = "apple,banana,orange";
const newText = text.split(",").join("\n");
console.log(newText);
// Output:
// apple
// banana
// orange

This method splits the text into an array of substrings using the comma as a delimiter, and then joins the array elements with a new line character.