Board index » delphi » begginer needs help on easy question...Emergency.

begginer needs help on easy question...Emergency.

I'm currently working on a program that has a while do loop controlled by
an array value compared to a control value.

I'm trying to do a linear search,

I want to increment the array index by one and compare the two values,
the index is a type char and I'm not sure how to increase it by one each
time.

So the question is how do I increase a char value by one.  That is go from
A to B, B to C, so on and so forth.

Any help is HUGELY appreciated.

  ************************************************************************
  *       Roy G. Wells           *   Life is short; take big bites; do   *
  * gsi09...@gsaix2.cc.gasou.edu * everything to the extreme. Moderation *
  * Georgia Southern University  * is for monks!  --Lazarus Long aka RAH *
  ************************************************************************

 

Re:begginer needs help on easy question...Emergency.


Quote
Roy Wells wrote:

[...]

Quote
> So the question is how do I increase a char value by one.  That is go
> from
> A to B, B to C, so on and so forth.

> Any help is HUGELY appreciated.

var
   c : char;
begin
   c := 'A';
   inc(c);  { c now = 'B' }
   inc(c,2); { c = now 'D' }
   c := chr(ord(c)+1); { c now 'E' }

Hope this helps,
Jochen

Re:begginer needs help on easy question...Emergency.


Quote
Roy Wells wrote:

> So the question is how do I increase a char value by one.  That is go from
> A to B, B to C, so on and so forth.

     Any enumerable type in Pascal (integers, characters, boolean,
enumerated types) can serve as the control variable of a FOR loop.

VAR
 letter : char;

BEGIN
 FOR letter := 'A' TO 'Z' DO use (letter);
END;

Bob Schor
Pascal Enthusiast

Re:begginer needs help on easy question...Emergency.


Quote
On Sun, 25 May 1997, Roy Wells wrote:

<Snip Stuff>
Quote

> So the question is how do I increase a char value by one.  That is go from
> A to B, B to C, so on and so forth.

> Any help is HUGELY appreciated.

There are 2 funtions chr and ord, ord returns the ascii value of a
character, and chr does the opposite.
To add one to a char all you have to do is :
chr(ord(value) + 1)
However you need to know what you want 'Z' to do when you add one to it.

Re:begginer needs help on easy question...Emergency.


On Sun, 25 May 1997 19:41:09 -0400, Roy Wells

Quote
<gsi09...@gsaix2.cc.GaSoU.EDU> wrote:
>I'm currently working on a program that has a while do loop controlled by
>an array value compared to a control value.

>I'm trying to do a linear search,

>I want to increment the array index by one and compare the two values,
>the index is a type char and I'm not sure how to increase it by one each
>time.

>So the question is how do I increase a char value by one.  That is go from
>A to B, B to C, so on and so forth.

>Any help is HUGELY appreciated.

The Pascal built-in function Succ() returns the subsequent item of a
enumerated type; e.g. Succ( 'A' ) will return 'B'.  There is also an
inverse function Pred() that might also be of use.

As previously posted, for your purposes, you can also index a for loop
with using a range of chars.

Quote
>  ************************************************************************
>  *       Roy G. Wells           *   Life is short; take big bites; do   *
>  * gsi09...@gsaix2.cc.gasou.edu * everything to the extreme. Moderation *    
>  * Georgia Southern University  * is for monks!  --Lazarus Long aka RAH *
>  ************************************************************************

HTH

Stephen Posey
slpo...@concentric.net

Re:begginer needs help on easy question...Emergency.


In Article<Pine.SOL.3.91.970527104211.16674B-100...@frodo.student.gu.edu.au>, <s1165...@frodo.student.gu.edu.au> writes:

Quote
> Path: news.NetVision.net.il!news-dc.gsl.net!news.gsl.net!news-fw.gsl.net!news.gsl.net!news-peer.gsl.net!howland.erols.net!feed1.news.erols.com!news.ecn.uoknor.edu!munnari.OZ.AU!bunyip.cc.uq.edu.au!newshost.gu.edu.au!frodo.student.gu.edu.au!s1165375
> From: "DAVID K. RALLS" <s1165...@frodo.student.gu.edu.au>
> Newsgroups: comp.lang.pascal.borland
> Subject: Re: begginer needs help on easy question...Emergency.
> Date: Tue, 27 May 1997 10:45:50 +1000
> Organization: Griffith University, Brisbane, Australia
> Lines: 17
> Message-ID: <Pine.SOL.3.91.970527104211.16674B-100...@frodo.student.gu.edu.au>
> References: <Pine.A41.3.96.970525192624.26804A-100...@gsaix2.cc.GaSoU.EDU>
> NNTP-Posting-Host: frodo.student.gu.edu.au
> Mime-Version: 1.0
> Content-Type: TEXT/PLAIN; charset=US-ASCII
> In-Reply-To: <Pine.A41.3.96.970525192624.26804A-100...@gsaix2.cc.GaSoU.EDU>
> Xref: news.NetVision.net.il comp.lang.pascal.borland:21502

> On Sun, 25 May 1997, Roy Wells wrote:

> <Snip Stuff>

> > So the question is how do I increase a char value by one.  That is go from
> > A to B, B to C, so on and so forth.

> > Any help is HUGELY appreciated.

> There are 2 funtions chr and ord, ord returns the ascii value of a
> character, and chr does the opposite.
> To add one to a char all you have to do is :
> chr(ord(value) + 1)
> However you need to know what you want 'Z' to do when you add one to it.

there is a simple solution look her:
just use a:=succ(x) and you will get the next value that you wanted!!!.
Da DA DA DA

blA BLA BLA
from shai brumer

Re:begginer needs help on easy question...Emergency.


<big snip>

Quote
>> On Sun, 25 May 1997, Roy Wells wrote:

>> <Snip Stuff>

>> > So the question is how do I increase a char value by one.  That is go from
>> > A to B, B to C, so on and so forth.

>> > Any help is HUGELY appreciated.

if x is a char, you can also use inc(x);   (TP6 & TP7 .. don't know
about others)
--
Pedt Scragg <postmas...@pedt.demon.co.uk>

In principle,   is there uncertainty that
Heisenberg was working his best in chaos?
=========================================

Other Threads