Delphi 7 : How To Split A String Into A TStringList
It's Delphi seven and I need to split a string into lines.
Specifically, I have a DFM as a string (pulled from a MySql database) and I want to split it into lines in a TStringList.
It looks something like this ...
'Oject Form1: TScriptForm'#$D#$A' Left = 0'#$D#$A' Top = 0'#$D#$A' Align = alClient'#$D#$A' BorderStyle = bsNone'#$D#$A' ClientHeight = 517'#$D#$A' ClientWidth = 993'#$D#$A' Color = clBtnFace'#$D#$A' Font.Charset = DEFAULT_CHARSET'#$D#$A' Font.Color = clWindowText'#$D#$A' Font.Height = -11'#$D#$A' Font.Name = 'MS Sans Serif''#$D#$A' Font.Style = []'#$D#$A' OldCreateOrder = False'#$D#$A' SaveProps.Strings = ('#$D#$A' 'Visible=False')'#$D#$A' PixelsPerInch = 96'#$D#$A' TextHeight = 13'#$D#$A'
eh
Answer: this turned out to be pretty much a non-question for me. Delphi sees the #$D#$A
as CR LF automatically, so that all I had to do was assign the string to the Text property of a TStringlist (this also stripped the single quotes from around each #$D#$A
). So, I only had to add a single line of code.
If the limiter had not been converted by Delphi then I think that @Roald van Doorn solution would have worked, so he gets awarded the answer.
Answer
It's easy to convert a string to a stringlist, all you need to do is the following steps.
Strip the leading
'
Replace all
'#$D#$A'
with #13#10 (thereby splitting the string in to lines again.Remove the trailing
'#$D#$A
Assign the resulting string to the StringList.Text
property, each line in the stringlist is now a line of the DFM file.
Related Questions
- → Index out of range (-1) when I click on any item in the TListBox
- → How can I display only specified database results based on TListbox items?
- → SQL How to sum from another table and insert in another table
- → Can a Windows dll retrieve its own filename?
- → TObjectList<T>.IndexOf giving incorrect result
- → Add field to FDMemTable in Delphi
- → What impact (if any) does Delphi 2009's switch to Unicode(/UTF16) have on executable size and memory footprint?
- → How to solve Delphi's [Pascal Fatal Error] F2084 Internal Error: LA33?
- → Do I have to use Disable/EnableControls when using Locate in a TClientDataSet?
- → What is the best way to make a Delphi Application completely full screen?
- → Is it possible to get a delphi project to create a lib file as the output of the project?
- → How to get currently logged in username?
- → How to fix the endless printing loop bug in Nevrona Rave