Game Maker's Garage Forum

Game Creation => SilverCreator => Topic started by: EqwanoX on December 26, 2011, 08:10:40 AM

Title: replace field method
Post by: EqwanoX on December 26, 2011, 08:10:40 AM

-Method name: ChangeField$

-Parameters: source$,separator$,fieldNumber,output$

-return type: string

-Method:
LET tempstr$ = ""
FOR field = 1 TO COUNTFIELDS(source$, separator$)
   IF field = fieldNumber THEN LET tempstr$+=output$ + separator$
   IF field <> fieldNumber THEN LET tempstr$+=NTHFIELD$(source$, separator$, field) + separator$
NEXT
LET tempstr$ = MID$(tempstr$, 1, LEN(tempstr$) - LEN(separator$))
RETURN tempstr$


EXAMPLE:
let string$="1,1,1,1,0,1,1,1"

//so if you wanted to change the 5th field to a "1" you would

let string$=changfield$(string$,",",5,"1")