使用 TStringList 的分隔符解析字符串,似乎也解析空格(Delphi)

发布于 2024-09-06 05:31:15 字数 173 浏览 3 评论 0原文

我有一个简单的字符串,由某个字符分隔,比如说逗号。我应该能够创建一个 TStringList 并将其分隔符设置为逗号,然后将 DelimitedText 设置为我想要解析的文本,并且应该自动解析它。

问题是,当我查看输出时,它还包含空格作为分隔符并分割我的结果。我怎样才能避免这种情况,或者有更好的方法来做到这一点。

I have a simple string which is delimited by some character, let's say a comma. I should be able to create a TStringList and set it's delimiter to a comma then set the DelimitedText to the text I want to parse and it should be automaticlly parsed.

The problem is when I look at the output it also includes spaces as delimiters and chops up my results. How can I avoid this, or is there a better way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情仇皆在手 2024-09-13 05:31:15

TStringList 上有一个 StrictDelimiter 属性。将其设置为 True,它将仅解析分隔符,而不解析空格。

There's a StrictDelimiter property on the TStringList. Set it to True and it will only parse on the delimiter, not the spaces.

鲜肉鲜肉永远不皱 2024-09-13 05:31:15

That's standard, documented behavior of the TStrings.DelimitedText property. You want to set the StrictDelimiter property to true to disable that behavior.

月寒剑心 2024-09-13 05:31:15

如果您使用的是 d7,您可以查看函数“ExtractStrings”

You can have a look on the function "ExtractStrings" , if you are using d7

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文