Solved

string in Delphi

Posted on 2003-11-12
5
383 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now