Solved

Cesario

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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