使用 TStringList 的分隔符解析字符串,似乎也解析空格(Delphi)
我有一个简单的字符串,由某个字符分隔,比如说逗号。我应该能够创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
这是
TStrings.DelimitedText
< 的标准记录行为/a> 属性。您想要设置StrictDelimiter
属性设置为 true 以禁用该行为。That's standard, documented behavior of the
TStrings.DelimitedText
property. You want to set theStrictDelimiter
property to true to disable that behavior.如果您使用的是 d7,您可以查看函数“ExtractStrings”
You can have a look on the function "ExtractStrings" , if you are using d7