insert string into string?
BlitzMax Forums/BlitzMax Programming/insert string into string?
| ||
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 |
| ||
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) |
| ||
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) |
| ||
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 |
| ||
Still had to run a loop, but Klepto2, you saved me the headache of having to do this all from scratch. Thanks again, -Garrett |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?code=1387 |