Page 1 of 1 1
Topic Options
#38870 - 2003-04-08 12:03 AM Convert value to a string
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Hello
How do I convert a value to a string ?
I cant find that in the manual.

/Mima

Top
#38871 - 2003-04-08 12:07 AM Re: Convert value to a string
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
for example :



break on

$n = 42 ;integer

$a = "" + $n ; theanswer

vartypename($n) ?

vartypename($a) ?

get $_



Of course this works also with the origin variable
_________________________



Top
#38872 - 2003-04-08 12:10 AM Re: Convert value to a string
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh hey, from the manual :

quote:
The following examples show the correct use of expressions in KiXtart:

$X = 1 + "20" ; $X type = integer / value = 21.

$X = &10 + &A ; $X type = integer / value = &1A (26).

$X = "1" + "20" ; $X type = string / value = '120'.

$X = @USERID + "1" ; $X type = string / value = 'USER1'.

"Current time = " + @time ; prints: "Current time = 12:34:00"

_________________________



Top
#38873 - 2003-04-08 12:10 AM Re: Convert value to a string
mima Offline
Hey THIS is FUN

Registered: 2002-01-25
Posts: 217
Loc: Jönköping, Sweden
Thanks
That worked....

/Mima

Top
#38874 - 2003-04-08 12:14 AM Re: Convert value to a string
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
With more recent versions of KiXtart you also have the C*() functions for specifically casting variable type.

Check your manual for CStr(). I think these were introduced in 4.10-ish.

It is no better than using "" to cast the type, but it is a bit more formal and it worth looking up to see how to cast (say) doubles and integers using CDbl() and CInt()

Top
#38875 - 2003-04-08 12:21 AM Re: Convert value to a string
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Arrggghh

that's what one gets from wanting to split replies for blasting post counts :

The ENT beat me while researching release version of CStr() [Eek!] [Eek!] [Eek!]
_________________________



Top
#38876 - 2003-04-08 12:27 AM Re: Convert value to a string
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
however,

for some of us this may be obvious but be aware :



break on

$n = 42
$o = 42
$p = 42

cstr($n+$o+$p) ? ; wrong

cstr(""+$n+$o+$p; correct

get $



[ 07. April 2003, 12:28: Message edited by: jpols ]
_________________________



Top
#38877 - 2003-04-07 01:02 PM Re: Convert value to a string
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Not quite right.

You are attempting to catenate the numbers as strings, so the "correct" way to do it is to explicitly cast the individual elements first:
code:
CStr($n)+CStr($o)+CStr($p)

Of course, that is a lot of unnecessary typing when you can use the auto-casting features of KiXtart:
code:
CStr($n)+$o+$p

The left-to-right processing of operators with equal precedence will ensure that this will work as well.

This may be a little heavy for Starters [Wink]

Top
#38878 - 2003-04-07 01:06 PM Re: Convert value to a string
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
again you are right ... I'll give that up for today and code some stuff

bye for now ... maybe tomorrow [Roll Eyes]
_________________________



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.136 seconds in which 0.109 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org