Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 06-29-2016, 06:10 AM
robert robert is offline
Senior Member
 
Join Date: Sep 2014
Posts: 382
Default reading after:

I have StringList in which my data is in this order

(Employees) Numbers: 5
(Salary) per-Anum: $20000
(Stock) Total-numbers: 415
(Rooms) Total: 6

there are 20-30 lines like this .. How can I read after : based on before : and after ()

Suppose I need to read (Salary) per-Anum: $20000

the result should be $2000 but based on per-Anum not on Salary
  #2  
Old 06-29-2016, 07:32 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

What do you want here:

#1 - Split the string into 3 parts => s1="(Salary)", s2="per-Anum", s3="$20000"

or

#2 - Find the value of a per-Anum, so search for "per-Anum" and take the value after the ":"
  #3  
Old 06-29-2016, 08:35 AM
robert robert is offline
Senior Member
 
Join Date: Sep 2014
Posts: 382
Default

#2 - Find the value of a per-Anum, so search for "per-Anum" and take the value after the ":"
  #4  
Old 06-29-2016, 09:18 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

Use the belwo function to search for the key names to get the values:

Code:
Function GetKeyValue(oSL : TStringlist; const sKeyName : String) : String;
var
         i : Integer;
begin
         Result := '';

         for i:=0 to oSL.Count-1 do begin
             if POS(sKeyName,oSL[i]) > 0 then
                result := Trim(Copy(oSL[i],Pos(':',oSL[i])+1, 10));
         end;
end;


Examples:

Code:
Showmessage( GetKeyValue(TheStringList,'per-Anum') );
//Or
Showmessage( GetKeyValue(TheStringList,'(Salary) per-Anum') );

Showmessage( GetKeyValue(TheStringList,'Total-numbers') );
__________________
Regards,
Abdulaziz Jasser
  #5  
Old 06-29-2016, 09:20 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

This you have done many times now

Make your searchstring "per-Anum" and add ": "
now you have a searchstring "per-Anum: "
Use Pos to see if it's in the line (you should read it line by line)
If Pos returns a greater value then 0 you use Copy starting at the result from Pos + then length of searchstring. The length you copy is the length of the line

Best is to have this in a function with input parameter the searchstring. This way you can re-use it for other searchstrings...

You've done a lot of string-slicing by now, so with this information you should be able to work something out.
If you still don't succeed I want to see some code, because by now you should be able to either write this yourself or finally start with my zen-garden design

And as always, what Jasser says...
  #6  
Old 06-29-2016, 10:27 AM
robert robert is offline
Senior Member
 
Join Date: Sep 2014
Posts: 382
Default

Thanks this solved my problem.

Last edited by robert; 06-29-2016 at 10:40 AM.
  #7  
Old 06-29-2016, 11:09 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

@Norrit

Best Regards,
__________________
Regards,
Abdulaziz Jasser
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:12 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.