Solved

Cesario

Posted on 2002-05-06
4
302 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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