问题描述
我在App_GlobalResources.resx
文件中保留了多个文本.
I'm keeping several texts in an App_GlobalResources.resx
file.
这些文本必须是多行的,我需要使它们包含换行符.但是,当我阅读内容时,所有换行符都消失了(打印了\r\n
,而不是作为CRLF 10 13
控制字符).
The texts have to be multi-line and I need to have them contain line feeds. However, when I read the contents, all line feeds are gone (\r\n
is printed, not as CRLF 10 13
control character).
我知道我可以通过在阅读内容时将\r\n
(或其他有关问题)重新替换为CRLF来解决此问题,但是我想知道为什么这些以文本为目标的resx文件忽略控制字符-而且CRLF很重要-如果有人知道是否有设置或某种设置可以使其自然运行.
I know that I could work around this by re-replacing \r\n
(or anything else for that matter) back to CRLF when I read the contents, but I wondered why these clearly text-targeted resx files ignore control characters - and CRLF is kind of important - and if anybody knows if there's a setting or something that would enable this to work naturally.
推荐答案
我使用VB.NET Express Edition对此进行了测试.
I used VB.NET Express Edition to test this.
在资源编辑器中(您可以指定资源的名称和字符串内容),将字符串内容用 + 分隔.
In the resource editor (where you can specify the name of the resource and string content) put the string content separated by +.
假设您要输入
hello
world
输入"hello",然后按 + 和"world".
Type "hello" followed by + and "world".
如果查看Resources.Resx文件(这是一个xml文件),则可以看到它创建了一个属性为xml:space="preserve"
的节点.
If you look at the Resources.Resx file (which is an xml file), you can see that it creates a node with the attribute xml:space="preserve"
.
第二个选项
此外,您可以手动编辑Resources.resx并将内容修改为在CDATA部分下.
Also, you can edit the Resources.resx manually and modify the content to be under CDATA section.
假定您具有名为"example"的字符串.在Resources.resx中进行搜索,然后将内容更改为在其中包含CDATA部分,而不是使用简单的值.
Assume that you have the string named "example". Search for it in Resources.resx and change the content to have CDATA section inside it as against having a simple value.
例如
<data name="example">
<![CDATA[
hello
world
1
2 3
4
]]> </data>
这篇关于.Net资源文件(App_GlobalResources)中的回车/换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!