?
Solved

merging strings within a tstringlist

Posted on 2004-08-26
4
Medium Priority
?
527 Views
Last Modified: 2010-04-05
hey all,
{ This function will take a tstringlist and combine all }
{ strings within that stringlist into a single string   }
{ within the same tstringlist. In other words, all      }
{ tsLST.strings[x] will be merged into tsLST.strings[0] }

Function CombineStrList(tsLST: TStringList): TStringList;
var
  i : integer;
  tsTMP: TStringList;
begin
  tsTMP := TStringList.Create;
  try
    tsTMP.Add('');
    for i:= 0 to tsLST.count -1  do  begin
      tsTMP[0] := tsTMP[0] + tsLST.strings[i];
    end;
    CombineStrList := tsTMP;
  finally
    tsTMP.Free;
  end;
end;

-------------
I know Im missing something easy, but when I tried to run this function I get an access violation error.
The following will make the err:
-------------
var
  tsComingSoon  : TStringList;

tsComingSoon := CombineStrList(tsComingSoon);
-------------

tsComingSoon has a few strings within the stringlist, and when I send it to the function it is combined correctly into tsTMP stringlist.
but when I try to access the new tsComingSoon stringlist I get the error.

any help would be nice :)

0
Comment
Question by:LMuadDIb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
bpana earned 500 total points
ID: 11908164
procedure CombineStrList(var tsLST: TStringList);
var
  s: string;
  i: integer;
begin
  s := '';
  for i := 0 to tsLST.Count - 1 do
  begin
    s := s + tsLST.Strings[i];
  end;
  tsLST.Clear;
  tsLST.Add(s);
end;
0
 
LVL 6

Expert Comment

by:bpana
ID: 11908174
use it as
CombineStrList(tsComingSoon);
0
 
LVL 8

Assisted Solution

by:Cesario
Cesario earned 200 total points
ID: 11908379
Hi,

Function CombineStrList(tsLST: TStringList): TStringList;
VAR
 NewList : TStringList;
begin
   NewList := TStringList.Create;
   NewList.Add ( StringReplace(tsLst.text,#13#10,'',[rfReplaceAll]));
   Result := NewList;
End;


best Regards

Cesario
0
 
LVL 4

Author Comment

by:LMuadDIb
ID: 11909736
gave the pts to bpana for the quick reply
but I added a few more pts and gave some to Cesario for his idea.
I would use Cesario idea, but I wanted to keep the integrity of the strings intact... didnt want to loose the formating sense the strings are made up of html code & text
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question