由于这个应用程序已经发展了多年,仍然有一些 INI 文件。我有一个使用 GetPrivateProfileString 读取条目的类。
在类的顶部,我们看到:
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
看起来有一个公共方法看起来像这样:
public string IniReadValue(string Section, string Key)
{
// If string greater than 254 characters (255th spot is null-terminator),
// string will be truncated.
const int capacity = 255;
StringBuilder temp = new StringBuilder(capacity);
int i = GetPrivateProfileString(Section, Key, "", temp,
capacity, this.m_Path);
return temp.ToString();
}
我最近注意到 GetPrivateProfileString 修剪它的数据。因此,如果我的 INI 文件有这样的条目:
SomeData= 注意这句话前后的三个空格。
它会像这样检索它(注意它被修剪到左右 - 忽略引号):
“注意这句话前后的三个空格。”
我不希望它修剪。这是我无法控制的吗?INI 文件不能在等号后有空格(例如 SomeData=)?