Set a character within a string
Blitz3D Forums/Blitz3D Beginners Area/Set a character within a string
| ||
Is it possible to change a character inside a string? I thought Mid$ would do this but it doesn't. Let's say I wanted to change the 2nd character but nothing else. So, Mid$(a$,2,1)="X" for example (though that doesn't work). |
| ||
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 |
| ||
I get a variable type mismatch from that. Ah, never mind, it's just the $ is missing off the Newstring just before the return. |