How do I remove the carriage return character (\r)
and the new line character(\n)
from the end of a string?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
If you are using multiple platforms you are safer using this method.
It will account for different newline and carriage-return characters.
I use lots of erasing level
and now we have a clean one row
This was too easy -- for me I'm filtering out certain email items. I'm writing my own custom email junk filter. With \r and/or \n in the string it was wiping out all items instead of filtering.
So, I just did filter = filter.Remove('\n') and filter = filter.Remove('\r'). I'm making my filter such that an end user can use Notepad to directly edit the file so there's no telling where these characters might embed themselves -- could be other than at the start or end of the string. So removing them all does it.
The other entries all work but Remove might be the easiest?
I learned quite a bit more about Regex from this post -- pretty cool work with its use here.
For us VBers:
s
being the original string.