Board index » delphi » finding a string position in a larger string

finding a string position in a larger string

Hi,

        I'm looking for a way to search for a certain string into a
larger string from a memo box.  For example: find the first '967' in
the string str='92765657483037466967' and store the position into an
integer var.

        position := str[17];
                         in my example.

        I need this 'cause I'll receive e-mails and I want to format
them automaticaly.

-------------------------

From - Fri Apr 18 20:57:58 1997
Received: from dialup9.direct-internet.net by cliff.uottawa.ca (AIX
4.1/UCB 5.64/4.03a)
          id AA42292; Sat, 19 Apr 1997 00:00:36 -0400
Message-Id: <9704190400.AA42292@cliff.uottawa.ca>
Date: Fri, 18 Apr 1997 20:51:34 -0400
From: Guillaume Boudreau <s1067...@uottawa.ca>
Organization: -= AihT NyC =-
X-Mailer: Mozilla 3.01 (Win95; I)
Mime-Version: 1.0
To: s1067...@uottawa.ca
Subject: Form posted from Mozilla
Content-Type: application/x-www-form-urlencoded
Status:  O
X-Mozilla-Status: 0001
Content-Length: 111

prenom=Boudreau&nom=Guillaume&ville=Gloucester&province=Ontario&username=Haplo&password=miori&envoyer=Envoyer

--------------------------

This is my message.  I want to keep only certains lines and format the
last line. So if I can select from the word 'From -' to 'Date:', I'll
be able to cut this part and keep the rest.  I use Memo1.SelLength and
Memo1.SelStart to select the part I want.

If you know a better way to do this, I'll be happy to hear from you.

                        Thanks

                                Guillaume - Haplo - Boudreau

 

Re:finding a string position in a larger string


Try looking up the Pos() function in the online help.

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Cernan <s1067...@uottawa.ca> wrote in article
<33644e04.3535...@news.uact.net>...

Quote
> Hi,

>    I'm looking for a way to search for a certain string into a
> larger string from a memo box.  For example: find the first '967' in
> the string str='92765657483037466967' and store the position into an
> integer var.

>    position := str[17];
>                     in my example.

Re:finding a string position in a larger string


In article <33644e04.3535...@news.uact.net>, s1067...@uottawa.ca says...

Quote
>        I'm looking for a way to search for a certain string into a
>larger string from a memo box.  For example: find the first '967' in
>the string str='92765657483037466967' and store the position into an
>integer var.

Try
   IF POS(SUBSTR,STRING) > 0 THEN
      SHOWMESSAGE('FOUND IT')
   ELSE
      SHOWMESSAGE('DIDNT FIND IT');

--
+---------------------------------------+-----------------+
: Klint{*word*151}                           : "Non rhyming    :
: EMail   : k...@kgb.une.edu.au           :  slang - the    :
: Snail   : A.B.R.I.                    :  possibilties   :
: Mail      University of New England   :  are useless"   :
:           Armidale NSW 2351 Australia :     L.J.J.      :
: Fax     : +61 67 725 376              :                 :
+---------------------------------------+-----------------+

Re:finding a string position in a larger string


|>Hi,
|>
|>        I'm looking for a way to search for a certain string into a
|>larger string from a memo box.  For example: find the first '967' in
|>the string str='92765657483037466967' and store the position into an
|>integer var.
|>
|>        position := str[17];
|>                         in my example.
|>
|>        I need this 'cause I'll receive e-mails and I want to format
|>them automaticaly.
|>
|>-------------------------
|>
|>From - Fri Apr 18 20:57:58 1997
|>Received: from dialup9.direct-internet.net by cliff.uottawa.ca (AIX
|>4.1/UCB 5.64/4.03a)
|>          id AA42292; Sat, 19 Apr 1997 00:00:36 -0400
|>Message-Id: <9704190400.AA42...@cliff.uottawa.ca>
|>Date: Fri, 18 Apr 1997 20:51:34 -0400
|>From: Guillaume Boudreau <s1067...@uottawa.ca>
|>Organization: -= AihT NyC =-
|>X-Mailer: Mozilla 3.01 (Win95; I)
|>Mime-Version: 1.0
|>To: s1067...@uottawa.ca
|>Subject: Form posted from Mozilla
|>Content-Type: application/x-www-form-urlencoded
|>Status:  O
|>X-Mozilla-Status: 0001
|>Content-Length: 111
|>
|>prenom=Boudreau&nom=Guillaume&ville=Gloucester&province=Ontario&username=Haplo
|>&password=miori&envoyer=Envoyer
|>
|>--------------------------
|>
|>This is my message.  I want to keep only certains lines and format the
|>last line. So if I can select from the word 'From -' to 'Date:', I'll
|>be able to cut this part and keep the rest.  I use Memo1.SelLength and
|>Memo1.SelStart to select the part I want.
|>
|>If you know a better way to do this, I'll be happy to hear from you.
|>
|>                        Thanks
|>
|>                                Guillaume - Haplo - Boudreau
Just use the pos function
var
  i : integer;

begin
    i := pos('967',orginalstring);

end;

Other Threads