简体   繁体   English

使用分隔符将字符串解析为TStringList,似乎也在空格上解析(Delphi)

[英]Parsing a string using a delimiter to a TStringList, seems to also parse on spaces (Delphi)

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. 我应该能够创建一个TStringList并将它的分隔符设置为逗号,然后将DelimitedText设置为我想要解析的文本,它应该自动解析。

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. 我怎样才能避免这种情况,或者有更好的方法来做到这一点。

There's a StrictDelimiter property on the TStringList. TStringList上有一个StrictDelimiter属性。 Set it to True and it will only parse on the delimiter, not the spaces. 将其设置为True,它只会解析分隔符,而不是空格。

That's standard, documented behavior of the TStrings.DelimitedText property. 这是TStrings.DelimitedText属性的标准记录行为。 You want to set the StrictDelimiter property to true to disable that behavior. 您希望将StrictDelimiter属性设置为true以禁用该行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM