Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Making a char from int
Thu, Sep 14 2017 5:20 AMPermanent Link

Matthew Jones

How can I make a char from an int? That is, I want

 myChar := 'a' + nRandom;

I thought the StringBuilder might solve it, but it needs a char. Is there a smart way?

(My current solution is an index into a string, which is clumsy)

--

Matthew Jones
Thu, Sep 14 2017 7:48 AMPermanent Link

Walter Matte

Tactical Business Corporation

Untested....

myChar  :=  chr(  ord('a') + nRandom );

Walter



"Matthew Jones" wrote:

How can I make a char from an int? That is, I want

 myChar := 'a' + nRandom;

I thought the StringBuilder might solve it, but it needs a char. Is there a smart way?

(My current solution is an index into a string, which is clumsy)

--

Matthew Jones
Thu, Sep 14 2017 8:37 AMPermanent Link

Matthew Jones

Walter Matte wrote:

>  myChar  :=  chr(  ord('a') + nRandom );

Ahah! Chr() being the magic. It would be nice if conversion routines like this were listed in the Casting section, which I looked in. Many thanks.

--

Matthew Jones
Fri, Sep 22 2017 2:40 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Ahah! Chr() being the magic. It would be nice if conversion routines like this were listed in the Casting section, which I looked in. Many thanks. >>

It's the same reason IntToStr isn't in the casting section.

Casts are type conversions that are performed based upon the types being type-compatible, whereas conversions like this are done between incompatible types.  In other words, they're simply used for ensuring the compiler understands what you already know, not providing any additional functionality/dimensions to the actual underlying value.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Sep 25 2017 3:41 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> It would be nice if conversion routines like this were listed in the Casting section, which I looked in. Many thanks. >>
>
> It's the same reason IntToStr isn't in the casting section.

I'm happy for it to be a link to the summary "conversion functions" page. 8-)

--

Matthew Jones
Image