Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cesario

Posted on 2002-05-06
4
Medium Priority
?
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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