删除 C# 转义字符
我在使用 VSTO 的 Evaluate 函数时遇到问题,该函数基本上是翻译 Excel 中的公式并返回值。
我所苦恼的是,如果我传递一个带有 " 字符的公式,C# 会自动在它旁边添加 \,我确实理解它为什么在那里,但它会导致函数失败,因为 \ 字符也试图进行求值,但是如果我使用字符串替换函数来删除 \ 字符,它会起作用
但是,我不能只删除 \ 字符,如果用户在单元格上键入 \ 字符怎么办?一个错误的答案,
谁能帮我解决这个问题
?使用@符号,也不起作用。
任何帮助将不胜感激。
I am having a problem when working with VSTO's Evaluate function, that function is basically translating a formula in Excel and return the value.
What I am struggling is if I pass a formula with " character, C# automatically add \ next to it, I do understand why it is there, but it is causing the function to fail since the \ character is trying to get evaluate as well, but if I use the string Replace function to remove the \ character, it works.
However, I cannot just remove \ character, what if the user do type a \ character on a cell? I will remove that regardless and causing my solution to give a wrong answer.
Can anyone help me to resolve that?
I have tried to use the @ sign, doesn't work neither.
Any help would be appreciate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您只是在调试器中看到 \ 字符。我在 C# 中从未见过会自动在任何字符串中插入转义字符。你能给我们一些示例代码吗?
I suspect that you are just seeing the \ character in the debugger. Nothing that I have ever seen in C# automatically inserts the escape character in any strings. Can you give us some example code?