sl [1] 应该返回'foo bar'
sl [1] code>'foo'
似乎分隔符现在是'^' AND ''
任何想法?
解决方案您应该为不被视为分隔符的空格设置 s1.StrictDelimiter:= True ,更多信息 here 。
由于您在不支持上述版本的版本中(如提交答案后所述),您有两个选项:
两个解决方法都不使用 StrictDelimiter 有限制:第一个需要一些未使用的字符,第二个不需要原始文本中的反向逗号和空格。
也许现在是升级到更新版本的Delphi的时候了):
I am having trouble with the delimiter in the TStringList Class. Take a look:
var s: string; sl: TStringList; begin sl := TStringList.Create; s := 'Users^foo bar^bar foo^foobar^barfoo'; sl.Delimiter := '^'; sl.DelimitedText := s; ShowMessage(sl[1]); end;sl[1] SHOULD return 'foo bar'
sl[1] DOES return 'foo'
It seems that the delimiter is now '^' AND ' '
Any ideas?
解决方案You should set s1.StrictDelimiter := True for spaces not to be considered delimiters, more info here.
Since you work in a version that does not support the above (as was clarified after the answer was submitted), you have two options:
Both workarounds not using StrictDelimiter have limitations: the first requires some unused character, and the second requires no inverted commas and spaces in the original text.
Maybe it's time to upgrade to a newer version of Delphi :)
更多推荐
Delphi:即使设置了分隔符,StringList分隔符始终是一个空格字符
发布评论