adding a number to a string

BlitzPlus Forums/BlitzPlus Beginners Area/adding a number to a string

Maddog(Posted 2005) [#1]
Hi all!

I'm unsig a hex-based map system and all the hexes have identifiers like "0101", "0102", etc.
So I display and save the identifiers as strings, because I want the leading zero included.

My question is, how can I add a number to a string?
So for example, what I would like to happen is: "0101" + 1 = "0102". This obviously won't work, the result being a concat like "01011".

So how can I add a number to a string?

greetz,
Andrik


CS_TBL(Posted 2005) [#2]
a$="0101"

a$=a$+1

OR

a$=a$+"1"


----------------------

result: a$="01011"


Maddog(Posted 2005) [#3]
CS_TBL, This is what I DON'T want to happen!

I'm searching for a way to get "0102" as a result, not "01011", that's just a concat.

If it's not possible, I'll have to make a function, no prob.

greetz,
Andrik


CS_TBL(Posted 2005) [#4]
oops read it wrong ^_^

a$="11111"
b$="123"

result$=add$(a$,b$)

Notify result$

End

Function add$(a$,b$)

	l1=Len(a$)
	l2=Len(b$)
	
	If l1>l2 l=l1 Else l=l2

	c=a$
	d=b$
	
	e$=c+d
	
	e$=RSet(e$,l)
	Return Replace(e$," ","0")
	
End Function



Maddog(Posted 2005) [#5]
Yeah,

That's what I thought...I use a similar function right now. I hoped I was overlooking something.

I'm an Oracle database programmer, so I'm kindda spoiled.. In Oracle pl/sql, you can simply add a number to a string.

thanx!
Andrik