Improve autocasting of numeric values in strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Improve autocasting of numeric values in strings

Post by c4s »

Works as expected with PB 5.10:

Code: Select all

str$ = "1" + 2
Debug str$  ; Output is "12", great! :)
...should work as well as the compiler knows that we are working with a string:

Code: Select all

str$ = 1 + "2"
Debug str$  ; Output should be "12"
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Puffolino
User
User
Posts: 49
Joined: Thu Jan 05, 2012 12:27 am

Re: Improve autocasting of numeric values in strings

Post by Puffolino »

Would also be fine to allow to set user defined casts, like {string}, {integer}, {double} etc.

Code: Select all

s.s="2"
debug {integer} Val( {string} 1 + "." + s ) / 3
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Improve autocasting of numeric values in strings

Post by c4s »

...well, that's not part of my feature request though. ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Improve autocasting of numeric values in strings

Post by Little John »

c4s wrote:Works as expected with PB 5.10:

Code: Select all

str$ = "1" + 2
Debug str$  ; Output is "12", great! :)
...should work as well as the compiler knows that we are working with a string:

Code: Select all

str$ = 1 + "2"
Debug str$  ; Output should be "12"
+ 1
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Improve autocasting of numeric values in strings

Post by ts-soft »

and the same for other types like:

Code: Select all

value.i = 1 + "2"
Debug value ; Output should be 3

value.i = "1" + 2
Debug value ; Output should be 3
:wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply