Convert integer in char????

bruno_lac

New Member
I want to know if there is a way to convert a number in char



exemple:
I want to convert 2 in "2".




Thank you for your futur help!!!!!
 

Crittar

Member
Bruno,

Use the STRING function:

DEFINE VARIABLE var1 AS INTEGER NO-UNDO.
DEFINE VARIABLE var2 AS CHARACTER NO-UNDO.

ASSIGN
var1 = 2
var2 = STRING(var1).

var2 will then contain the value "2".

Hope this helps.
:rolling:
 

Chris Schippers

New Member
A high-tech solution

DEFINE VARIABLE var1 AS INTEGER NO-UNDO.
DEFINE VARIABLE var2 AS CHARACTER NO-UNDO.

ASSIGN
var1 = 2
var2 = chr(var1 + 48).

:awink: Sorry, could not help myself.....
 

Crittar

Member
You're welcome, Bruno.

Nice one Chris - But I prefer to follow the "kiss" principle myself...
(Keep It Simple Stupid).

:awink: :jester: :penny:
 

tsspdx

New Member
I'd characterize Bruno's solution (chr(var1 + 48) ) as low-tech. It's the STRING function that's high tech.

The CHR solution only works, of course, under unstated assumptions about the contents of var1 (integers from 0 to 9) and language (single byte ASCII). But since it's likely to cause future problems, it's probably a good choice in this time of high unemployment in the IT sector.

:awink:
 
Top