C# 相当于 stripcslashes 函数?
我正在处理一个项目,其中包括从彩信网关获取彩信并将图像存储在磁盘上。
这包括使用收到的 Base64 编码字符串并将其作为 zip 存储到 Web 服务器。然后打开该 zip,并检索图像。
我们已设法将其存储为 zip 文件,但它已损坏且无法打开。
网关的文档非常稀疏,我们只有一个 php 示例可以依赖。我认为我们已经弄清楚如何“翻译”其中的大部分内容,除了 PHP 函数 stripcslashes(inputvalue)。任何人都可以阐明如何在 C# 中做同样的事情吗?
我们感谢任何帮助!
I am working with a project that includes getting MMS from a mms-gateway and storing the image on disk.
This includes using a received base64encoded string and storing it as a zip to a web server. This zip is then opened, and the image is retrieved.
We have managed to store it as a zip file, but it is corrupted and cannot be opened.
The documentation from the gateway is pretty sparse, and we have only a php example to rely on. I think we have figured out how to "translate" most of it, except for the PHP function stripcslashes(inputvalue). Can anyone shed shed any light on how to do the same thing in c#?
We are thankful for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
stripcslashes() 在较长的字符串中查找“\x”类型元素(其中“x”可以是任何字符,或者可能不止一个)。如果“x”未被识别为有意义,它只会删除“\”,但如果它确实将其识别为有效的 C 样式转义序列(即“\n”是换行符;“\t”是制表符等)。 ),据我了解,已识别的字符被插入: \t 将被字符串中的制表符(我认为是 0x09)替换。
我不知道有什么简单的方法可以让 .net 框架在不自己构建类似功能的情况下执行相同的操作。这显然不是很难,但您需要知道要处理哪些转义序列。
如果您碰巧知道(或通过检查您的 base64 文本发现)输入中唯一需要处理的是特定的一两个序列(例如制表符),那么它会变得非常容易,以下代码片段显示了使用String.Replace():
当然,如果你真的只是想删除所有斜杠:
stripcslashes() looks for "\x" type elements within longer strings (where 'x' could be any character, or perhaps, more than one). If the 'x' is not recognised as meaningful, it just removes the '\' but if it does recognise it as a valid C-style escape sequence (i.e. "\n" is newline; "\t" is tab, etc.), as I understand it, the recognised character is inserted instead: \t will be replaced by a tab character (0x09, I think) in your string.
I'm not aware of any simple way to get the .net framework to do the same thing without building a similar function yourself. This obviously isn't very hard, but you need to know which escape sequences to process.
If you happen to know (or find out by inspecting your base64 text) that the only thing in your input that will need processing is a particular one or two sequences (say, tab characters), it becomes very easy and the following snippet shows use of String.Replace():
Of course, if you really do simply want to remove all the slashes: