我收到了有趣的 % 符号,我该如何摆脱它们?
我正在尝试解析来自 url 编码的身份验证服务器的响应。但是,当我这样做时,我收到 \r\n 字符。我不需要在文本中包含这些字符,因为我需要能够运行查找空格但不适用于这些转义字符的正则表达式。
所以基本上返回的字符串是:
ClientIP=192.168.20.31%0d%0aUrl%3d%2fflash%2f56553550_hi%3funiqueReference%3d27809666.mp4
url 解码后它是:
192.168.20.31\r\nUrl=/flash/56553550_hi?uniqueReference=27809666.mp4
所以你看我不希望它有 \r \n 等我想要:
"192.168.20.31 Url=/flash/56553550_hi?uniqueReference=27809666.mp4"
作为 c# 中的逐字字符串。
这可能吗?或者我是否必须对 \r 执行 string.replace 并替换为“”?
Im trying to parse a response from an authentication server that is url encoded. However when I do it I am getting \r\n characters. And I need to not have these in my text as I need to be able to run a regular expression that looks for white space but doesnt work with these escape characters.
So basically the string returned is:
ClientIP=192.168.20.31%0d%0aUrl%3d%2fflash%2f56553550_hi%3funiqueReference%3d27809666.mp4
After url decoding it it is:
192.168.20.31\r\nUrl=/flash/56553550_hi?uniqueReference=27809666.mp4
So you see I dont want it to have \r \n etc I want to have:
"192.168.20.31 Url=/flash/56553550_hi?uniqueReference=27809666.mp4"
As a verbatim string in c#.
Is this possible? Or do I have to do a string.replace on \r and replace with " "?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在对字符串进行 URL 解码之前,将
%0d%0a
替换为%20
,或者将\r\n
替换为后。
由于数据存在于原始字符串中,因此您不能仅将其删除而不进行替换。
Either replace
%0d%0a
with%20
before URL decoding the string, or the\r\n
withafter.
Since the data exists in the original string, you can't just make it go away without replacing it.