Solved

Cesario

Posted on 2002-05-06
4
287 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
ID: 6990928
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
ID: 6990987
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
ID: 6991127
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
ID: 6991139
no problem, dark_king
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
Newbie Thread Programming 1 138
Working this component WebCopy with proxy, help 3 76
Delphi : could not find program, '...exe' 2 144
Delphi selector screen 2 69
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
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: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 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

12 Experts available now in Live!

Get 1:1 Help Now