以下代码有效:
var
SL: TStrings;
begin
SL := TStringList.Create;
try
SL.Add(Format('%s=%s', ['Alex', '14.05.1984']));
ShowMessage(SL.Values['Alex']);
finally
SL.Free;
end;
end;
虽然此代码不起作用(无法从名称获取值):
var
SL: TStrings;
begin
SL := TStringList.Create;
try
SL.Delimiter := '|'; // <=== changed from default '=' char
SL.QuoteChar := '"'; // <=== added
SL.StrictDelimiter := True; // <=== added
SL.Add(Format('%s=%s', ['Alex', '14.05.1984']));
ShowMessage(SL.Values['Alex']); // <=== returns an empty string
finally
SL.Free;
end;
end;
有人可以帮助我吗?
被修改
program Sample;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes,
Dialogs;
var
SL: TStrings;
begin
try
SL := TStringList.Create;
try
SL.Delimiter := '|';
SL.QuoteChar := '"';
SL.StrictDelimiter := True;
// SL.Add(Format('%s=%s', ['Alex', '14.05.1984']));
SL.LoadFromFile('ReplacementPairs.txt');
ShowMessage(SL.Values['Alex']);
finally
SL.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
ReplacementPairs.txt文件的内容是:
Alex|14.05.1984
Paul|10.07.2015
Edith|18.11.1961