Add new line to a string
A simple one!
In most programming languages, you can add a new line to a string by concatenating the original string with a newline character (\n
or \r\n
depending on the platform).
Here are a few examples:
JavaScript
const originalString = "Hello";
const newString = originalString + "\nWorld";
console.log(newString); // Output: "Hello\nWorld"
Python
original_string = "Hello"
new_string = original_string + "\nWorld"
print(new_string) # Output: "Hello\nWorld"
Java
String originalString = "Hello";
String newString = originalString + "\nWorld";
System.out.println(newString); // Output: "Hello\nWorld"
C#
string originalString = "Hello";
string newString = originalString + Environment.NewLine + "World";
Console.WriteLine(newString); // Output: "Hello\nWorld" (on Windows) or "Hello\rWorld" (on macOS/Linux)
Note that the newline character (\n
) is used on most platforms, but on Windows, you may need to use \r\n
to get a proper newline.