我收到了有趣的 % 符号,我该如何摆脱它们?

发布于 2024-10-07 17:56:58 字数 555 浏览 1 评论 0原文

我正在尝试解析来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-10-14 17:57:03

在对字符串进行 URL 解码之前,将 %0d%0a 替换为 %20,或者将 \r\n 替换为 后。

由于数据存在于原始字符串中,因此您不能仅将其删除而不进行替换。

Either replace %0d%0a with %20 before URL decoding the string, or the \r\n with after.

Since the data exists in the original string, you can't just make it go away without replacing it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文