Parsing a string using a delimiter to a TStringList, seems to also parse on spaces (Delphi)
Asked Answered
F

3

6

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.

Feder answered 17/6, 2010 at 17:15 Comment(0)
F
22

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

Fernand answered 17/6, 2010 at 17:33 Comment(1)
Note: This is only available from Delphi 2005 (or 2006) only. If you are using an older version, you can create your own subclass of TStringList with a "StrictDelimitedText" property. Unfortunately SetDelimitedText is both private and non-virtual (in D7 at least) so you can't override it.Stockbroker
S
5

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

Susansusana answered 17/6, 2010 at 17:34 Comment(0)
P
5

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

Pasteur answered 18/6, 2010 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.