Science, Tech, Math › Computer Science How to Parse a Delimited String Into a String List Print Roberto Westbrook / Getty Images Computer Science Delphi Programming Delphi Tutorials Advanced PHP Programming Perl Python Java Programming Javascript Programming C & C++ Programming Ruby Programming Visual Basic View More By Zarko Gajic Zarko Gajic Computer Science Expert MSCS, Computer Science, University of Osijek Zarko Gajic is experienced in SQL and has working knowledge of DB systems such as MS SQL Server, Firebird, Interbase, and Oracle. He is also proficient in XML, DHTML, and JavaScript. Learn about our Editorial Process Updated on February 24, 2019 There are many times when you need to split a string into an array of strings by using a character as a separator. For example, a CSV ("comma" separated) file might have a line like "Zarko;Gajic;;DelphiGuide" and you want this line to be parsed into 4 lines (strings) "Zarko", "Gajic", "" (empty string) and "DelphiGuide" using the semi-colon character ";" as a delimiter. Delphi provides several methods to parse a string, but you might find that neither one does exactly what you need. For example, the ExtractStrings RTL method always uses quote characters (single or double) for delimiters. Another approach is to use the Delimiter and DelimitedText properties of the TStrings class—but unfortunately, there is a bug in the implementation ("inside" Delphi) where the space character is always used as a delimiter. Read More String Handling Routines: Delphi Programming By Zarko Gajic The only solution to parsing a delimited string is to write a method of your own: Delimited String Example ~~~~~~~~~~~~~~~~~~~~~~~~~procedure ParseDelimited(const sl : TStrings; const value : string; const delimiter : string) ;vardx : integer;ns : string;txt : string;delta : integer;begindelta := Length(delimiter) ;txt := value + delimiter;sl.BeginUpdate;sl.Clear;trywhile Length(txt) > 0 dobegindx := Pos(delimiter, txt) ;ns := Copy(txt,0,dx-1) ;sl.Add(ns) ;txt := Copy(txt,dx+delta,MaxInt) ;end;finallysl.EndUpdate;end;end;~~~~~~~~~~~~~~~~~~~~~~~~~ Usage (fills in Memo1) :ParseDelimited(Memo1.lines,'Zarko;Gajic;;DelphiGuide',';') Cite this Article Format mla apa chicago Your Citation Gajic, Zarko. "How to Parse a Delimited String Into a String List." ThoughtCo, Aug. 27, 2020, thoughtco.com/parse-a-delimited-string-1057564. Gajic, Zarko. (2020, August 27). How to Parse a Delimited String Into a String List. Retrieved from https://www.thoughtco.com/parse-a-delimited-string-1057564 Gajic, Zarko. "How to Parse a Delimited String Into a String List." ThoughtCo. https://www.thoughtco.com/parse-a-delimited-string-1057564 (accessed April 23, 2024). copy citation