insert string into string?

BlitzMax Forums/BlitzMax Programming/insert string into string?

Garrett(Posted 2006) [#1]
Before I try this the long way, is there a quick way of inserting a string into
another string at certain positions? Such as, I want to insert commas into
a string that contains the size of a file, the file has all numbers and no comma
seperations between hundreds, thousands etc;

Raw string currently holds say this: 5472392
I want to insert the commas so the string ends up as: 5,472,392

Any quick way of doing this? Or as I planned on looping with some splitting of
the string and putting the string back together with new data, the only way to
go?

Thanks,
-Garrett


klepto2(Posted 2006) [#2]
Function StringInsert:String(Source:String , Entry:String , Pos:Int = 0)
	Local Temp:String = Source[..Pos]
	Temp:+ Entry
	Temp:+ Source[Pos..]
	Return Temp
End Function

Print StringInsert("Hello Friend" , "my " , 6)




Dreamora(Posted 2006) [#3]
Looping and using Mid / left / right is the way to go :) (as string operations always create a new string there isn't much reason for a different solution anyway)


Garrett(Posted 2006) [#4]
Klepto2; Hey, that's looking pretty sweet, and it's probably shorter and less
complicated than what I had in mind. Thanks a bunch! :-)

Dreamora; Klepto2's code will likely satisfy my hunger. ;-) Thanks :-)

-Garrett


Garrett(Posted 2006) [#5]
Still had to run a loop, but Klepto2, you saved me the headache of having to
do this all from scratch.

Thanks again,
-Garrett


Perturbatio(Posted 2006) [#6]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1387