Delete a letter from a string

Blitz3D Forums/Blitz3D Programming/Delete a letter from a string

slenkar(Posted 2005) [#1]
Run this program:
player_name$="Trev"
Replacement$=Right$(player_name$,1)
Replace(player_name$,replacement$,"Z")
Print player_name
Stop
WaitKey

it should say TreZ instead of Trev


Beaker(Posted 2005) [#2]
player_name$="Trev"
Replacement$=Right$(player_name$,1)
player_name$ = Replace(player_name$,Replacement$,"Z")
Print player_name
Stop
WaitKey



slenkar(Posted 2005) [#3]
THANKS!!



my player name input functions work ok,
but if you press backspace when there is nothing to delete the screen goes blank and I cant work out why

EDIT-
got it working but the REPLACE command removes all instances of a letter from a string if they are next to each other, dont know how to stop this


Rottbott(Posted 2005) [#4]
Function Backspace$(St$)

  If Len(St$) = 0 Then Return ""

  Return Left$(St$, Len(St$) - 1)

End Function



PowerPC603(Posted 2005) [#5]
Also check out the Chr$(letter) and Asc(letter$) commands, so you can replace that very long function "Convert_to_string$".

Chr$() accepts a ASCII value and converts it to a character (like your function), while Asc() accepts a character and converts it back to a ASCII value.


slenkar(Posted 2005) [#6]
thanks Rott and PowerPC,
once Im finished would it make a good entry to the code archives?
I cant find anything similar in there,

the reason I am doing this is because it makes it possible to use cool bitmap fonts instead of the 'unprofessional' INPUT command,


_PJ_(Posted 2005) [#7]

once Im finished would it make a good entry to the code archives?
I cant find anything similar in there,



Sure, why not? Any contributions would always be useful to someone. Well, that's my opinion anyway!