Nim: [Bug]strip() not clear white-space escape characters

Created on 4 Sep 2018  路  7Comments  路  Source: nim-lang/Nim

strip() should clear "\n" from string because it's just whitespace escape characters
example:
import strutils
var x = "\n".strip()
echo(x)

in python it's does the job like it's should be
https://stackoverflow.com/questions/24646461/python-why-does-str-strip-automatically-removes-all-the-escape-characters?lq=1

Stdlib

Most helpful comment

@muhammad-al-baqir-khalid

The empty line is because of echo "" 馃槃

All 7 comments

It seems that this is because \n is not listed here https://nim-lang.org/docs/strutils.html#Whitespace

Thanks so much a pull added

Hmm, I am not able to reproduce this issue on Nim devel (built today).

Evaluating:

import strutils
echo "芦" & "\n string \n \n\n".strip() & "禄"
echo "芦" & "\n".strip() & "禄"

gives:

芦string禄
芦禄

it's keep one line empty
try
import strutils
echo("\n \n").strip()

@muhammad-al-baqir-khalid

The empty line is because of echo "" 馃槃

@muhammad-al-baqir-khalid See stdout.write (example) if you want to echo without newlines.

@kaushalmodi Thanks 馃憤 i know it but i just forget echo make new line

Was this page helpful?
0 / 5 - 0 ratings