Solved

string in Delphi

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

20 Experts available now in Live!

Get 1:1 Help Now