Solved

data processing split string by another string

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now