Solved

data processing split string by another string

Posted on 2004-08-17
4
297 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 154
Create a path if not exists 7 89
Tidtcpserver listening on multiports? 1 35
How to save the image in the .cds File ClientDataSet? 1 22
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 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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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