Solved

Cesario

Posted on 2002-05-06
4
281 Views
Last Modified: 2010-04-04
Cesario is it possible to use a second position.

0023fe12ceef;d2151;d215-1
0023fe12f0ff;d2152:d215-2
00c11098cce3;d2153;d215-3

And get to separate result.

Ex.. I search for  0023fe12f0ff and get d2152 and d215-2 in to String1 and String2

-----------------------------------------------------

From: Cesario  Date: 05/02/2002 06:29AM PST  
HELLO Dark King,

try this code:

procedure TForm1.Button1Click(Sender: TObject);
var
 s : tstringlist;
begin
 s := tStringlist.create;
 s.loadfromfile ( 'c:\demo.txt');
 s.text := StringReplace(S.Text,';','=',[rfReplaceAll] );

 // now search for 0023fe12f0ff
 ShowMessage( S.Values['0023fe12f0ff']);

 // now test it with a rong value :
 ShowMessage( S.Values['x023fe12f0ff']);
 you will get an empty string

 s.free;
end;


Best Regards

Cesario  
0
Comment
Question by:Dark_King
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
based on cesario sample
added with my spitstr-function

//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;

procedure TForm1.Button1Click(Sender: TObject);
var
  s : tstringlist;
  s_value : String;
  s_part_1 : String;
  s_part_2 : String,
begin
  s := tStringlist.create;
  s.loadfromfile ( 'c:\demo.txt');
  s.text := StringReplace(S.Text,';','=',[rfReplaceAll] );

  // now search for 0023fe12f0ff
  s_value := S.Values['0023fe12f0ff'];
  ShowMessage('Full Value:'+ s_value);
  //now get the first part
  s_part_1 := splitstr(s_value,'=');
  ShowMessage('First Part:'+ s_part_1);
  //as there no more to split, and the rest is in s_value
  s_part_2 := s_value;
  ShowMessage('Second_part:'+ s_part_2);

  // now test it with a rong value :
  ShowMessage( S.Values['x023fe12f0ff']);
  //you will get an empty string
  s.free;
end;

just from head, not tested

meikl ;-)

0
 
LVL 8

Accepted Solution

by:
Cesario earned 200 total points
Comment Utility
Dear Dark King,

Try this code

procedure TForm1.Button1Click(Sender: TObject);
VAR
  MyData : tStrings;
  Cnt    : Integer;
  p      : Integer;
  SearchResult : String;
  TempString   : String;
  Value1       : string;
  Value2       : string;
begin
  MyData := tStringList.Create;
  Try
    MyData.LoadFromFile ('C:\Data.Txt');

    // Change the first ";" to =
    For Cnt := 0 To MyData.Count-1 Do
    Begin
      p := Pos(';',MyData.Strings[cnt]);
      IF P>0 Then
      Begin
        TempString :=MyData.Strings[cnt];
        TempString[p] := '=';
        MyData.Strings[cnt] := TempString;
      End;
    End;

    // now Search for the Values
    SearchResult := MyData.Values['0023fe12ceef'];
    IF SearchResult <> '' Then
    Begin
      Value1 := Copy ( Searchresult,1,Pos(';',Searchresult)-1);
      System.Delete ( SearchResult,1,Pos(';',Searchresult));
      Value2 := SearchResult;
      ShowMessage ( Format('Value1  : %s',[Value1])+#13+
                    Format('Value1  : %s',[Value2]));
    End;

  Finally
    MyData.Free;
  End;
end;

Best Regards

Cesario
0
 
LVL 6

Author Comment

by:Dark_King
Comment Utility
Great….

Sorry kretzschmar  but this one a already started with Cesario
I just needed to put some points in to get is attention.  
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
no problem, dark_king
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

11 Experts available now in Live!

Get 1:1 Help Now