Borland BCB5 TInifile 使用 Readstring() 忽略引号?

Borland BCB5 TInifile ignores Quotation Marks with Readstring()?

我不太熟悉 Borland C++ Builder 5,遇到了一个问题。

我有一个 INI 文件:

[Section1]
Ident1="myUser1"
Ident2=myPassword

我用这段代码读取了用户名和密码值:

{
auto_ptr<TIniFile> ifile(new TIniFile(myinifile));
AnsiString InternalUser= ifile->ReadString("Section1", "Ident1", "Defaultuser");
AnsiString InternalPassword= ifile->ReadString("Section1", "Ident2","Defaultpassword");
}

函数声明如下:

virtual AnsiString __fastcall ReadString(const AnsiString Section, const AnsiString Ident, const AnsiString Default);

预期输出:

Ident1="myUser1" (with ")
Ident2=myPassword

实际输出:

Ident1=myUser1 (without ")
Ident2=myPassword

在尝试调试时,我收到很多 Delphi 系统调用,我不知道,也找不到相关文档,例如 LStrToPCharLStrClr

我期待某种 Trim() 但我错了。

请问有人能给我解答一下吗?

似乎不​​是 Borland 引起的问题,而是底层 Windows API 例程的行为。使用 MSVC 的快速检查给出了相同的结果。

#include "stdafx.h"
#include <Windows.h>

int _tmain(int argc, _TCHAR* argv[])
{    
    TCHAR buf[400];
    GetPrivateProfileString( _T("Test"), _T("Test"), _T("Default"), &buf[0], 400, _T("test.ini"));
    _tprintf(_T("%s\n"),&buf);

    return 0;
}

INI 文件:

[Test]
Test="string with quotes"

结果:

string with quotes

这是documented behavior:

If the string associated with lpKeyName is enclosed in single or double quotation marks, the marks are discarded when the GetPrivateProfileString function retrieves the string.

此 class 是对已弃用已久的 Windows INI 文件 API 的包装。读取值的函数是 GetPrivateProfileString 并且它的文档说:

If the string associated with lpKeyName is enclosed in single or double quotation marks, the marks are discarded when the GetPrivateProfileString function retrieves the string.

因此您观察到的行为。