Solved

string in Delphi

Posted on 2003-11-12
5
398 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
[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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

739 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