Delete a letter from a string
Blitz3D Forums/Blitz3D Programming/Delete a letter from a string 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
Dim players_characters(7) Global player_name$ Global actual_character$ Global number_of_characters Graphics 800,600,16,1 SetBuffer=BackBuffer() While number_of_characters<7 Cls FlushKeys() While Not players_characters(number_of_characters) Cls players_characters(number_of_characters)=GetKey() Text 400,200,"Please enter your name:",True,True Text 400,300,player_name+"$",True,True Flip Wend actual_character$=0 actual_character$=convert_to_string(players_characters(number_of_characters)) If players_characters(number_of_characters)<>13 And players_characters(number_of_characters)<>8 player_name$=player_name$+actual_character$ number_of_characters=number_of_characters+1 Else If players_characters(number_of_characters)=13 Exit EndIf If players_characters(number_of_characters)=8 delete_letter() EndIf EndIf Flip Wend Print "This program completed succesfully, Your name is:"+player_name WaitKey() End Function delete_letter() If number_of_characters>0 players_characters(number_of_characters)=0 actual_character="" number_of_Characters=number_of_characters-1 players_characters(number_of_characters)=0 Replacement$=Right$(player_name$,1) player_name$=Replace$(player_name$,replacement$,"") Cls Text 400,200,"Please enter your name:",True,True Text 400,300,player_name,True,True Flip EndIf End Function Function Convert_to_string$(letter) Select letter Case 97 Return "a" Case 98 Return "b" Case 99 Return "c" Case 100 Return "d" Case 101 Return "e" Case 102 Return "f" Case 103 Return "g" Case 104 Return "h" Case 105 Return "i" Case 106 Return "j" Case 107 Return "k" Case 108 Return "l" Case 109 Return "m" Case 110 Return "n" Case 111 Return "o" Case 112 Return "p" Case 113 Return "q" Case 114 Return "r" Case 115 Return "s" Case 116 Return "t" Case 117 Return "u" Case 118 Return "v" Case 119 Return "w" Case 120 Return "x" Case 121 Return "y" Case 122 Return "z" Case 65 Return "A" Case 66 Return "B" Case 67 Return "C" Case 68 Return "D" Case 69 Return "E" Case 70 Return "F" Case 71 Return "G" Case 72 Return "H" Case 73 Return "I" Case 74 Return "J" Case 75 Return "K" Case 76 Return "L" Case 77 Return "M" Case 78 Return "N" Case 79 Return "O" Case 80 Return "P" Case 81 Return "Q" Case 82 Return "R" Case 83 Return "S" Case 84 Return "T" Case 85 Return "U" Case 86 Return "V" Case 87 Return "W" Case 88 Return "X" Case 89 Return "Y" Case 90 Return "Z" End Select End Function
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
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.
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.
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,
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,
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!