RTF 中的撇号问题

发布于 2024-08-21 12:34:52 字数 394 浏览 6 评论 0原文

我在自定义 CRM Web 应用程序(大约 2003 年的旧 VB.Net)中有一个函数,它从数据库中获取一组字段,并将它们与一组基于 RTF 的模板文档中的占位符合并。这些生成合并的信件和文档。该代码本质上循环遍历 RTF 模板文件的每一行,并用数据库记录中的文本替换占位符值的任何实例。我遇到的问题是,用户将某种类型的撇号粘贴到 Web 应用程序中(因此粘贴到数据库中),但在生成的 RTF 文件中无法正确呈现。它的渲染效果是这样的——’。

我需要一种方法来发现代码中这个无效的撇号并将其​​替换为有效的撇号。不幸的是,当我将无效的撇号粘贴到 Visual Studio 编辑器中时,它会转换为正确的撇号。所以我需要另一种方式来表达这个无效撇号的值。不幸的是,我对 unicode 和其他编码了解不多,所以我在此寻求帮助。

有什么想法吗?

I have a function within a custom CRM web application (old VB.Net circa 2003) that takes a set of fields from a database and merges them with palceholders in a set of RTF based template documents. These generate merged letters and documentation. The code essentially loops through each line of the RTF template file and replaces any instances of the placeholder values with text from a database record. The issue I'm having is that users have pasted a certain type of apostrophe into the web app (and therefore into the database) that is not rendering correctly in the resulting RTF file. It is rendering like this - ’.

I need a way to spot this invalid apostrophe in the code and replace it with a valid one. Unfortunately when I paste the invalid apostrophe into the Visual Studio editor it gets converted into the correct one. So I need another way to express this invalid apostrophe's value. Unfortunately I do not know a great deal about unicode and other encodings so I'm calling out for help with this.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

话少情深 2024-08-28 12:34:52

如果您真的只是想弄清楚该字符是什么,您可能需要尝试将其粘贴到文本编辑器中,例如 ultraedit。它有一个十六进制模式,您可以翻转到查看实际的底层字节。

为了在找出字符后进行替换,您需要在 Vb 中执行类似的操作,

text.Replace(ChrW(2001), "'")

请注意,您可能无法使用文本编辑器轻松找出它,因为它也可能会被来自剪贴板。您可能想要从代码中打印一些 ascii 值的调试信息。您可以使用 AscW 函数来执行此操作。

我忍不住认为这实际上可能只是在写出流时指定要使用的正确编码的情况。假设您使用 StreamWriter,您可以在构造函数中指定它。我猜你实际上想要 ASCII 给定你的要求。

    oWriter = New System.IO.StreamWriter(path, False, System.Text.Encoding.ASCII)

If you really just want to figure out what the character is you might want to try and paste it into a text editor like ultraedit. It has a hex mode that you can flip to to see the actual underlying bytes.

In order to do the replace once you've figured out the character you'd do something like this in Vb,

text.Replace(ChrW(2001), "'")

Note that you might not be able to figure it out easily using the text editor because it might also get mangled by paste from the clipboard. You might want to either print some debug of the ascii values from code. You can use the AscW function to do that.

I can't help but think that it may actually simply be a case of specifying the correct encoding to use when you write out the stream though. Assuming you're using a StreamWriter you can specify it on the constructor. I'm guessing you actually want ASCII given your requirement.

    oWriter = New System.IO.StreamWriter(path, False, System.Text.Encoding.ASCII)
枕花眠 2024-08-28 12:34:52

看起来您可能想要对 8 位范围 (>255) 之外的字符进行编码。

您可以根据 维基百科文章 使用 \uNNNN 来执行此操作。

It looks like you probably want to encode characters out of the 8 bit range (>255).

You can do that using \uNNNN according to the wikipedia article.

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