Solved

string in Delphi

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 100
Delphi Mdi application Child forms get behind control 7 308
Delphi 2 77
Delphi Seattle StructureView color 1 21
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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