Solved

data processing split string by another string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 39
TEMBEDDEDWB how can i change its user agent ? 8 45
Dynamically Created Query 3 50
Firemonkey DbLookupComboBox equivalent ? 2 32
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 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

15 Experts available now in Live!

Get 1:1 Help Now