Set a character within a string

Blitz3D Forums/Blitz3D Beginners Area/Set a character within a string

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

function ReplaceLetterAtXWithY$(OldString$,CharacterPos,NewCharacter$)
if len(OldString)=0 or CharacterPos<1 or CharacterPos>Len(OldString) then return ""
NewCharacter=left(NewCharacter,1)
IF CharacterPos=1 then return NewCharacter+right(OldString,Len(OldString)-1)
If CharacterPos=Len(OldString) then return left(OldString,len(OldString)-1)+NewCharacter
NewString$=Left(OldSTring,CharacterPos-1)+NewCharacter+Right(OldString,Len(OldString)-(CharacterPos))

return NewString$
end function