如何将大字符串添加到 TStringList

How to add a large string to TStringList

我想使用 TStringList 来解析 "ipconfig /all" 的输出。

如果我使用 AddStrings,整个 return 字符串将在第一个元素中结束。我尝试使用 LoadFromStream 但编译器给了我

no matching member function for call to 'LoadFromStream'

candidate function not viable: no known conversion from 'String' (aka 'System::UnicodeString') to 'System::Classes::TStream *' for 1st argument

关于如何将字符串放入流中或将 return 字符串放入我的 TStringList 中的其他方法有什么想法吗?

TStringList *IPConfig = new TStringList;
IPConfig->AddStrings(ExecuteExternalFile("ipconfig", "/all", false));  //everything returned ends up in one element defeating the purpose of using a TStringList
IPConfig->LoadFromStream(ExecuteExternalFile("ipconfig", "/all", false));  //won't compile

感谢您引导我回到 Delimiter 属性。我重新访问它并发现其中有一个错误,要求您将 StrictDelimiter 设置为 true 否则将始终通过 space 分隔您的文本。现在它工作正常。谢谢!

IPConfig->StrictDelimiter = true;
IPConfig->Delimiter = '\n';
IPConfig->DelimitedText = ExecuteExternalFile("ipconfig", "/all", false);

您可以将 TStringStreamLoadFromStream() 一起使用:

TStringList *IPConfig = new TStringList;
TStringStream *Strm = new TStringStream(ExecuteExternalFile("ipconfig", "/all", false));
IPConfig->LoadFromStream(Strm);
delete Strm;
...
delete IPConfig;