How to turn off the prettier trailing comma in VS Code?

Since you are working on the Tour of Heroes project, it is maybe the .editorconfig file there that introduces conflicts with your VSCode Prettier settings. Try adding the following .prettierrc file at the root of your project : { “trailingComma”: “none” } The .prettierrc file has the highest priority over any setting, so it should …

Read more

Remove a trailing slash from a string(changed from url type) in JAVA

There are two options: using pattern matching (slightly slower): s = s.replaceAll(“/$”, “”); or: s = s.replaceAll(“/\\z”, “”); And using an if statement (slightly faster): if (s.endsWith(“https://stackoverflow.com/”)) { s = s.substring(0, s.length() – 1); } or (a bit ugly): s = s.substring(0, s.length() – (s.endsWith(“https://stackoverflow.com/”) ? 1 : 0)); Please note you need to use …

Read more

How can I remove a trailing newline?

Try the method rstrip() (see doc Python 2 and Python 3) >>> ‘test string\n’.rstrip() ‘test string’ Python’s rstrip() method strips all kinds of trailing whitespace by default, not just one newline as Perl does with chomp. >>> ‘test string \n \r\n\n\r \n\n’.rstrip() ‘test string’ To strip only newlines: >>> ‘test string \n \r\n\n\r \n\n’.rstrip(‘\n’) ‘test …

Read more

How to remove leading and trailing zeros in a string? Python

What about a basic your_string.strip(“0”) to remove both trailing and leading zeros ? If you’re only interested in removing trailing zeros, use .rstrip instead (and .lstrip for only the leading ones). More info in the doc. You could use some list comprehension to get the sequences you want like so: trailing_removed = [s.rstrip(“0”) for s …

Read more

How do I remove a trailing newline?

Try the method rstrip() (see doc Python 2 and Python 3) >>> ‘test string\n’.rstrip() ‘test string’ Python’s rstrip() method strips all kinds of trailing whitespace by default, not just one newline as Perl does with chomp. >>> ‘test string \n \r\n\n\r \n\n’.rstrip() ‘test string’ To strip only newlines: >>> ‘test string \n \r\n\n\r \n\n’.rstrip(‘\n’) ‘test …

Read more