-
Python:
text = "Hello, world!\n" text = text.rstrip("\n") print(text)
-
JavaScript:
let text = "Hello, world!\n"; text = text.replace(/\n$/, ""); console.log(text);
-
Java:
String text = "Hello, world!\n"; text = text.replaceAll("\\n$", ""); System.out.println(text);
-
C#:
string text = "Hello, world!\n"; text = text.TrimEnd('\n'); Console.WriteLine(text);
-
Рубин:
text = "Hello, world!\n" text = text.chomp puts text
-
PHP:
$text = "Hello, world!\n"; $text = rtrim($text, "\n"); echo $text;
Эти примеры демонстрируют, как удалить конечные символы новой строки из текстовой строки в Python, JavaScript, Java, C#, Ruby и PHP соответственно.