 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
steven Guest
|
Posted: Mon Jan 26, 2004 3:23 pm Post subject: string delimiter |
|
|
I'm moving from D5 to D8.
<p state="puzzled">
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced it by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly the
same? How do I instruct LoadFromFile to create a new string for each line?
</p>
TIA
Steven
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Mon Jan 26, 2004 3:52 pm Post subject: Re: string delimiter |
|
|
Heh, and what defines a 'line' in HTML ?
Not #13 or #13#10 for sure
..... perhaps '>' or maybe '<' or maybe not ...
On Mon, 26 Jan 2004 15:23:01 GMT, "steven"
wrote:
| Quote: | I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced it by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly the
same? How do I instruct LoadFromFile to create a new string for each line?
/p
TIA
Steven
|
|
|
| Back to top |
|
 |
steven Guest
|
Posted: Mon Jan 26, 2004 4:08 pm Post subject: Re: string delimiter |
|
|
(top post repaired)
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | On Mon, 26 Jan 2004 15:23:01 GMT, "steven" <stevenPANTSvh (AT) pandora (DOT) be
wrote:
I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced it
by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList
and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly
the
same? How do I instruct LoadFromFile to create a new string for each
line?
/p
TIA
Steven
Heh, and what defines a 'line' in HTML ?
Not #13 or #13#10 for sure
.... perhaps '>' or maybe '<' or maybe not ...
|
The file has CR+LF's
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Mon Jan 26, 2004 4:42 pm Post subject: Re: string delimiter |
|
|
On Mon, 26 Jan 2004 16:08:12 GMT, "steven" <stevenPANTSvh (AT) pandora (DOT) be>
wrote:
<snip>
| Quote: |
The file has CR+LF's
|
But ... HTML does not care about them
|
|
| Back to top |
|
 |
Tom de Neef Guest
|
Posted: Tue Jan 27, 2004 12:35 am Post subject: Re: string delimiter |
|
|
"steven" <stevenPANTSvh (AT) pandora (DOT) be> wrote
| Quote: | I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced it
by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly
the
same? How do I instruct LoadFromFile to create a new string for each line?
/p
TIA
Steven
|
If it loads as one line (ie MyStringlist.count=1 after the LoadFromFile)
then the file did not have end-of-line markers (#13#10 or vise verse).
And Yes, Tmemo.lines and Tstringlist should behave the same with regards to
LoadFromFile (since that method is inherited from Tstrings).
Tom
|
|
| Back to top |
|
 |
David Reeve Guest
|
Posted: Tue Jan 27, 2004 12:42 am Post subject: Re: string delimiter |
|
|
"steven" <stevenPANTSvh (AT) pandora (DOT) be> wrote
| Quote: | (top post repaired)
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:4015377e.22380409 (AT) news (DOT) btclick.com...
On Mon, 26 Jan 2004 15:23:01 GMT, "steven" <stevenPANTSvh (AT) pandora (DOT) be
wrote:
I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced
it
by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList
and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly
the
same? How do I instruct LoadFromFile to create a new string for each
line?
/p
TIA
Steven
Heh, and what defines a 'line' in HTML ?
Not #13 or #13#10 for sure
.... perhaps '>' or maybe '<' or maybe not ...
The file has CR+LF's
|
Are you sure of that? I suspect your memo also loaded as a single line, but
showed OK because you had word wrap enabled.
Dave
|
|
| Back to top |
|
 |
VBDis Guest
|
Posted: Tue Jan 27, 2004 3:35 am Post subject: Re: string delimiter |
|
|
Im Artikel <phaRb.6298$Lu7.359484 (AT) phobos (DOT) telenet-ops.be>, "steven"
<stevenPANTSvh (AT) pandora (DOT) be> schreibt:
| Quote: | Now the complete file is loaded in a single string. Aren't TStringList and
TMemo.Lines both supposed to be TStrings?
|
No. TMemo is a "component", that uses an TStrings object (property Lines) to
store the text to display.
| Quote: | Shouldn't they behave exactly the same?
|
No. A TStringList doesn't display anything.
A TMemo wraps long lines into multiple lines, on display, whereas other
controls simply cut the text at the right margin of the control.
| Quote: | How do I instruct LoadFromFile to create a new string for each line?
|
When the TStringList loads everything into an single string, then I assume that
your file consists of one line (without any CR/LF). That's no problem for HTML,
since HTML uses special tags (<p>...) to indicate where the following text
should be displayed in a new line.
So the first question is: what do you consider as a "line"? A CR/LF delimited
line of (unformatted) text, or an paragraph of HTML text?
In the first case, but lacking any CR/LF delimiters, you'll have to specify
e.g. the length of a line, and then break the text into strings of that length
yourself. If you want word-wrapping, too, you'll have to write a bit more code
;-)
In the latter case you'd better use an HTML component, that can filter out all
the invisible HTML tags, and provides the visible text only, neatly broken into
titles, paragraphs, cells or other kinds of formatted text items.
DoDi
|
|
| Back to top |
|
 |
steven Guest
|
Posted: Tue Jan 27, 2004 5:56 am Post subject: Re: string delimiter |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | On Mon, 26 Jan 2004 16:08:12 GMT, "steven"
wrote:
snip
The file has CR+LF's
But ... HTML does not care about them
|
Well, I do.
There's a coding difference between searching a single string and searching
a stringlist.
|
|
| Back to top |
|
 |
steven Guest
|
Posted: Tue Jan 27, 2004 6:40 am Post subject: Re: string delimiter |
|
|
"David Reeve" <dree4456 (AT) big-pond (DOT) net.au> wrote
| Quote: |
"steven" <stevenPANTSvh (AT) pandora (DOT) be> wrote in message
news:MXaRb.6346$2q7.354440 (AT) phobos (DOT) telenet-ops.be...
(top post repaired)
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:4015377e.22380409 (AT) news (DOT) btclick.com...
On Mon, 26 Jan 2004 15:23:01 GMT, "steven" <stevenPANTSvh (AT) pandora (DOT) be
wrote:
I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced
it
by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't
TStringList
and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave
exactly
the
same? How do I instruct LoadFromFile to create a new string for each
line?
/p
TIA
Steven
Heh, and what defines a 'line' in HTML ?
Not #13 or #13#10 for sure
.... perhaps '>' or maybe '<' or maybe not ...
The file has CR+LF's
Are you sure of that?
|
I was. But I opened the file with a text editor to see it in hex, and it
appears the editor automagically converts LF to CR/LF when it opens the
file. Hence the confusion.
So, no, it's just LF.
| Quote: | I suspect your memo also loaded as a single line, but
showed OK because you had word wrap enabled.
|
Could have been, but it didn't.
1. File with only LFs:
StringList loads as a single line
Memo loads as multiple lines
2. File with CR+LF:
Both load as multiple lines
Weird...
--
Steven
|
|
| Back to top |
|
 |
steven Guest
|
Posted: Tue Jan 27, 2004 6:43 am Post subject: Re: string delimiter |
|
|
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote
| Quote: | "steven" <stevenPANTSvh (AT) pandora (DOT) be> wrote in message
news:phaRb.6298$Lu7.359484 (AT) phobos (DOT) telenet-ops.be...
I'm moving from D5 to D8.
p state="puzzled"
I have a text-file (HTML to be precise), which I load into a TMemo:
MemoDebug.Lines.LoadFromFile(AFileName);
Works fine. Now the TMemo was only there for debugging, so I replaced it
by
a TStringList:
MyStringList.LoadFromFile(AFileName);
Now the complete file is loaded in a single string. Aren't TStringList
and
TMemo.Lines both supposed to be TStrings? Shouldn't they behave exactly
the
same? How do I instruct LoadFromFile to create a new string for each
line?
/p
TIA
Steven
If it loads as one line (ie MyStringlist.count=1 after the LoadFromFile)
then the file did not have end-of-line markers (#13#10 or vise verse).
And Yes, Tmemo.lines and Tstringlist should behave the same with regards
to
LoadFromFile (since that method is inherited from Tstrings).
|
They don't seem to behave the same if the file has just LF, without CR.
See my reply to David.
--
Steven
|
|
| Back to top |
|
 |
steven Guest
|
Posted: Tue Jan 27, 2004 6:53 am Post subject: Re: string delimiter |
|
|
"VBDis" <vbdis (AT) aol (DOT) com> wrote
| Quote: | Im Artikel <phaRb.6298$Lu7.359484 (AT) phobos (DOT) telenet-ops.be>, "steven"
[email]stevenPANTSvh (AT) pandora (DOT) be[/email]> schreibt:
Now the complete file is loaded in a single string. Aren't TStringList
and
TMemo.Lines both supposed to be TStrings?
No. TMemo is a "component", that uses an TStrings object (property Lines)
to
store the text to display.
Shouldn't they behave exactly the same?
No. A TStringList doesn't display anything.
|
Correct. But I was comparing TStringlist (default property is Strings, which
is a TStrings) with TMemo.Lines, which is also a TStrings.
| Quote: |
A TMemo wraps long lines into multiple lines, on display, whereas other
controls simply cut the text at the right margin of the control.
How do I instruct LoadFromFile to create a new string for each line?
When the TStringList loads everything into an single string, then I assume
that
your file consists of one line (without any CR/LF). That's no problem for
HTML,
since HTML uses special tags (<p>...) to indicate where the following text
should be displayed in a new line.
So the first question is: what do you consider as a "line"? A CR/LF
delimited
line of (unformatted) text, or an paragraph of HTML text?
In the first case, but lacking any CR/LF delimiters, you'll have to
specify
e.g. the length of a line, and then break the text into strings of that
length
yourself. If you want word-wrapping, too, you'll have to write a bit more
code
;-)
In the latter case you'd better use an HTML component, that can filter out
all
the invisible HTML tags, and provides the visible text only, neatly broken
into
titles, paragraphs, cells or other kinds of formatted text items.
|
I wish I didn't say anything about HTML. The file's semantics is not
important. What I want to do is find a specific character sequence in a file
with several lines of text.
You want to know if it loads as a single string or as a stringlist. The
search code is not complicated in either case, but the code is different.
--
Steven
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Tue Jan 27, 2004 12:35 pm Post subject: Re: string delimiter |
|
|
On Tue, 27 Jan 2004 06:53:24 GMT, "steven" <stevenPANTSvh (AT) pandora (DOT) be>
wrote:
<snip>
| Quote: |
I wish I didn't say anything about HTML. The file's semantics is not
important. What I want to do is find a specific character sequence in a file
with several lines of text.
You want to know if it loads as a single string or as a stringlist. The
search code is not complicated in either case, but the code is different.
|
And I wish I had not said anything about a TStringList ...
You have an HTML file downloaded from a Unix machine
Unix uses #10 as new line
DOS uses #13#10 as new line
Mac uses #13 as new line
However HTML does not give a toss about #13 or #10
- it just treats them as a #32
- and it does not give a toss about multiple #32s
two #32s are treated as one #32
Your best bet is to get the file into one string
- remove all #13s and #10s
Then use PosEx() to find the stuff you want to extract
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Tue Jan 27, 2004 1:17 pm Post subject: Re: string delimiter |
|
|
On Tue, 27 Jan 2004 12:35:53 +0000 (UTC), [email]erewhon (AT) nowhere (DOT) com[/email] (J
French) waffled on about something:
| Quote: | On Tue, 27 Jan 2004 06:53:24 GMT, "steven"
wrote:
snip
I wish I didn't say anything about HTML. The file's semantics is not
important. What I want to do is find a specific character sequence in a file
with several lines of text.
You want to know if it loads as a single string or as a stringlist. The
search code is not complicated in either case, but the code is different.
And I wish I had not said anything about a TStringList ...
You have an HTML file downloaded from a Unix machine
Unix uses #10 as new line
DOS uses #13#10 as new line
Mac uses #13 as new line
However HTML does not give a toss about #13 or #10
- it just treats them as a #32
- and it does not give a toss about multiple #32s
two #32s are treated as one #32
Your best bet is to get the file into one string
- remove all #13s and #10s
Then use PosEx() to find the stuff you want to extract
|
PosEx?
Where's that come from? Sounds interesting...
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Tue Jan 27, 2004 3:12 pm Post subject: Re: string delimiter |
|
|
On Tue, 27 Jan 2004 13:17:48 +0000, Dodgy
<Dodgy (AT) earth (DOT) planet.universe> wrote:
<snip>
| Quote: |
Then use PosEx() to find the stuff you want to extract
PosEx?
Where's that come from? Sounds interesting...
Dodgy.
|
Apparently about Delphi 7, Borland realized that they did not have the
equivalent of BASIC's (not just VB) InStr()
They also introduced such useful things as LeftStr() and RightStr()
I use D4 so have to roll my own
If you want a hepped up InStr() this might help
- it does not use Boyers-Moore - but I have doubts about that
algorithms viability for one off searches
{#################################################################
Result := InStr( 2, 'ABCDEF', 'BCD' ) rev: 20/6/02 JF
}
Function InStr( Start:Integer; Const BigStr,SmallStr:String):Integer;
Var
L9, L8, Max, P: Integer;
BigL, SmallL: Integer;
C : Char;
Begin
Result := 0; // Set Default
// Should be illegal
If Start <= 0 Then
Start := 1;
// Take String Lengths
BigL := Length( BigStr );
SmallL := Length( SmallStr );
// '' Target always returns 0
If BigL = 0 Then
Exit;
// '' Convention returns Start
If SmallL = 0 Then
Begin
Result := Start;
Exit;
End;
// Find last possible Start pos
Max := BigL - SmallL + 1;
If Max < Start Then
Exit;
// Take First Char of Search String
C := SmallStr[1];
// Hunt Forwards for a match
For L9 := Start To Max Do
If BigStr[L9] = C Then // If first Char Found
Begin
P := L9 + SmallL - 1;
For L8 := SmallL DownTo 2 Do // Scan Backwards
Begin
If BigStr[P] <> SmallStr[L8] Then
Break;
P := P - 1;
End;
// Success - we know first Char matches
If P = L9 Then
Begin
Result := L9;
Break;
End;
End;
End;{InStr}
///////////////////////////////////////////////////
//
// Table of UpperCase Chars for InStrI
//
Var
cmnCharArray :Array [0 .. 255] Of Char;
cmnCharArrayInstalledFlag :Boolean = False;
Procedure LS_InstallCharArray;
Var
L9 :Integer;
Begin
If cmnCharArrayInstalledFlag Then Exit;
cmnCharArrayInstalledFlag := True;
For L9 := 0 To 255 Do
cmnCharArray[L9] := UpperCase( String(Chr(L9)) )[1];
End;
///////////////////////////////////////////////////
{#################################################################
Case Insensitive Comparison
Result := InStrI( 2, 'ABcdEF', 'bCd' ) 25/10/02 JF
}
Function InStrI( Start:Integer; Const
BigStr,SmallStrIn:String):Integer;
Var
SmallStr :String;
L9, L8, Max, P :Integer;
BigL, SmallL :Integer;
C : Char;
Begin
LS_InstallCharArray; // Setup Table - if necessary
Result := 0; // Set Default
SmallStr := UpperCase( SmallStrIn );
// Should be illegal
If Start <= 0 Then
Start := 1;
// Take String Lengths
BigL := Length( BigStr );
SmallL := Length( SmallStr );
// '' Target always returns 0
If BigL = 0 Then
Exit;
// '' Convention returns Start
If SmallL = 0 Then
Begin
Result := Start;
Exit;
End;
// Find last possible Start pos
Max := BigL - SmallL + 1;
If Max < Start Then
Exit;
// Take First Char of Search String
C := SmallStr[1];
// Hunt Forwards for a match
For L9 := Start To Max Do
If cmnCharArray[Ord(BigStr[L9])] = C Then // If first Char
Found
Begin
P := L9 + SmallL - 1;
For L8 := SmallL DownTo 2 Do // Scan Backwards
Begin
If cmnCharArray[Ord(BigStr[P])] <> SmallStr[L8] Then
Break;
P := P - 1;
End;
// Success - we know first Char matches
If P = L9 Then
Begin
Result := L9;
Break;
End;
End;
End;{InStrI}
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Tue Jan 27, 2004 9:50 pm Post subject: Re: string delimiter |
|
|
steven wrote:
| Quote: | "J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:40154439.25640149 (AT) news (DOT) btclick.com...
On Mon, 26 Jan 2004 16:08:12 GMT, "steven"
wrote:
snip
The file has CR+LF's
But ... HTML does not care about them
Well, I do.
There's a coding difference between searching a single string and
searching a stringlist.
|
dosearch('my test string');
dosearch(mystringlist.text);
Doesn't look like a hell of a difference to me!
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|