Solved

data processing split string by another string

Posted on 2004-08-17
4
299 Views
Last Modified: 2010-04-05
Im reading the output from a serial port, it has an event whenever a new line is reached
so the output is buffored per line. the output looks something like

----- somedata some data
     some data
     some data
     some data
------ new data  new
     new  new
     new
     new
     new
    ldkslsdjf

the sequence starts with -------, now I want to have a buffor where I oneventdata
it would add to the string I have the new data then phrase it looking for ------ the new sequence if there is one then the the thing would get processed. Now I tried looking for a split function that would allow the delimeter to be another string but couldnt find one. Can anyone help me?

Tom
0
Comment
Question by:T0masz
[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 7

Expert Comment

by:LRHGuy
ID: 11826546
Try something like:

I:=pos('-- ',inputdata);
if I>0 then begin
  leftside:=copy(inputdata,1,I+2);
  rightside:=copy(inputdata,I+3,255);  // everything after the "-- "
end;
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 11828103
hi,

//this simple function, does what you need
//it returns the first part as result, and shorten the given string
//for next item simple call again
//if there are no items, then the given string becomes empty
function SplitStr(Var AString : String; ADelim : String) : String;
var APos : Integer;
begin
  Result := '';
  APos := Pos(ADelim,AString);
  if APos > 0 then
  begin
    Result := Copy(AString,1,APos-1);
    AString := copy(Astring,APos+length(Adelim),MaxLongInt);
  end
  else
  begin
    Result := AString;
    AString := '';
  end;
end;

//a usage sample
procedure TForm1.Button1Click(Sender: TObject);
var s : String;
begin
 ListBox1.Clear;
 s := edit1.text;
 while s <> '' do
   listbox1.items.add(SplitStr(s,edit2.text));
end;

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11878241
any results?
0
 

Author Comment

by:T0masz
ID: 12056714
Sorry, I took some time off :)

It works :)
Thanks
Tom
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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