Удаление завершающих символов новой строки из текстовой строки на разных языках программирования

  1. Python:

    text = "Hello, world!\n"
    text = text.rstrip("\n")
    print(text)
  2. JavaScript:

    let text = "Hello, world!\n";
    text = text.replace(/\n$/, "");
    console.log(text);
  3. Java:

    String text = "Hello, world!\n";
    text = text.replaceAll("\\n$", "");
    System.out.println(text);
  4. C#:

    string text = "Hello, world!\n";
    text = text.TrimEnd('\n');
    Console.WriteLine(text);
  5. Рубин:

    text = "Hello, world!\n"
    text = text.chomp
    puts text
  6. PHP:

    $text = "Hello, world!\n";
    $text = rtrim($text, "\n");
    echo $text;

Эти примеры демонстрируют, как удалить конечные символы новой строки из текстовой строки в Python, JavaScript, Java, C#, Ruby и PHP соответственно.