Solved

string in Delphi

Posted on 2003-11-12
5
390 Views
Last Modified: 2012-05-04
I have 2 problems
1. i want to extract a substring from a string with a specified position
example : John like to play soccer
i want to extraxct the substring like to play
2.i have a memo with the structure
Name:(thename)#9Age:(age)years
memo contain about 20 lines
i want to store all the names and the respective ages (array or something or better database)
how can i do that
thnks
0
Comment
Question by:tinti
  • 2
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 55 total points
ID: 9729574
Hi,

1.
var s1,s2: string;
begin
  s1 := 'John like to play soccer';
  s2 := Copy(s1, 6, 12); // s2 is 'like to play'
...

2.
var
  i,k: integer;
  a: array [1..50,1..2] of string;
begin
  for i := 0 to Memo1.Lines.Count - 1 do begin
    k := Pos(#9, Memo1.Lines[i]);
    if k > 0 then begin
      a[i,1] := Copy(Memo1.Lines[i], 1, k - 1); // the name
    end;

    k := Pos(':', Memo1.Lines[i]);
    if k > 0 then begin
      a[i,2] := Copy(Memo1.Lines[i], k+1, Length(Memo1.Lines[i]); // the age
      k := Pos'years', a[i,2];
      if k > 0 then begin
        a[i,2] := Copy(a[i,2], 1, k - 1); // remove 'years' from the string
      end;
    end;
  end;
...

Regards, Geo
0
 

Expert Comment

by:TomasThil
ID: 9730678
Hi,
Have a look at TStringManager. You will find it at: http://www.geocities.com/ericdelphi/StrMan.html. Great string routines and easy to use. Install it and where ever you like to use it just add StrMan to your uses. You will get a global object called sm. So it's like sm.replace(....,...,..,..);


Tomas Thil
0
 

Expert Comment

by:saienlyh
ID: 9731308
var s1,s2: string;
begin
  s1 := 'John like to play soccer';
  s2 := Copy(s1, 6, 12); // s2 is 'like to play'
...
0
 
LVL 17

Expert Comment

by:geobul
ID: 9731407
saienlyh,

What are trying to say with that copy of what I've written?

Regards, Geo
0
 

Expert Comment

by:saienlyh
ID: 9731464
geobul,
to my way of thinking Result so
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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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