在 User.config 文件中存储单个字符(制表符、换行符、任何字符) [英] Store a single character (tab, new line, any character) in User.config file
问题描述
我想在 User.config(或 App.config)文件中存储和保存单个字符.普通字符可以很容易地保存,但是当涉及到像 \t
, \n
这样的特殊字符时,我无法存储它们,因为 VS2012 说它不是一个字符.我用 \t
的 XML 标记修改 User.config 文件,它是 	
它有效!但是,当再次保存时,它失败了.当我在代码 Properties.Settings.Default.delim = '\t'
中分配这样的 \t
字符并调用 Save
方法时,仅编程存储 \0
字符.我无法在代码中存储 XML 等效字符串,因为它是一个字符串,而不是一个字符,我正在尝试将一个字符串分配给一个字符.
I want to store and save back a single character in User.config (or App.config) file. Normal characters can be hold easily, but when it comes to special characters like \t
, \n
I cannot store them because VS2012 says it is not a character. I modify the User.config file with XML tags of \t
which is 	
it works! However, when it comes to save it again, it fails. When I assign \t
character like this in code Properties.Settings.Default.delim = '\t'
and call Save
method, program only stores \0
character. I cannot store XML equivalent string in code because it is a string, not a character and I'm trying to assign a string to a character.
对此有什么想法吗?
推荐答案
您可以通过转换为 int
来存储字符的十进制 ASCII 代码,然后将其转换回 char
在你的程序中.
You could store the decimal ASCII code for the character by converting to an int
, and convert it back to a char
in your program.
例如
char charToSave = '\t';
int code = (int)charToSave;
SaveCharToUserConfig(code);
...
int code = GetCodeFromUserConfig();
char savedChar = (char)code;
这篇关于在 User.config 文件中存储单个字符(制表符、换行符、任何字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!