如何使用 PowerShell 删除特殊格式(制表符、回车键、退格键、换行符等)
我想使用 PowerShell 删除这些回车符(或者至少我认为它们是什么),但我我这样做有困难。我用过:
-替换“`n”,“”
-替换“`t”、“”
-替换“`b”、“”
-替换“`r”、“”
似乎没有任何效果。有什么建议吗?
I want to remove these carriage returns (or at least I think that's what they are) using PowerShell but I am having trouble doing so. I've used:
-replace "`n",""
-replace "`t",""
-replace "`b",""
-replace "`r",""
nothing seems to work. any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想对删除进行手术,一种粗略但有效的方法是使用 .Net ASCII 编码对象来获取有问题的字符的数值:
对于文本行中的每个字符,该代码将输出字符,然后输出其数值。它看起来像这样(括号中的字符不会出现在实际输出中,它们在那里是为了澄清):
通过针对 CSV 文件的一行运行它,您应该能够检测到需要删除的内容。然后,您可以通过将数值转换回其表示的 ASCII 字符来执行替换。例如,这两个语句都会从文本中删除“b”字符:
If you want to be surgical about the deletions, one crude but effective method is to use a .Net ASCII encoding object to get a numeric value of the offending character(s):
For every character in a line of your text, that code will output the character and then its numeric value. It will look something like this (characters in parentheses won't appear in the actual output, they're there for clarification):
By running it against one line of your CSV file, you should be able to detect what needs to be stripped. You can then perform a replacement by converting the numeric value back into the ASCII character it represents. For instance, both of these statements will delete a `b character from your text:
尝试使用正则表达式:
或者如果值是数字
try using regex:
or if values are numbers