how to change a letter in a string
BlitzPlus Forums/BlitzPlus Programming/how to change a letter in a string
| ||
I need to overwrite a letter in position X within a string. Can anyone point me to the obvious solution, please? (-_-) |
| ||
If you want to replace one specific position:string2$=left(string1$,postion-1)+NewCharacter$+mid$(string1$,position+1) If you want to replace all occurances of a particular string to another one, regardless of position: string1$=replace$(string1$,"a","@") ' Replaces all occurences of 'a' with '@' |
| ||
The idea is that a word like "??????", which is displayed for the user, should appear to be overwritten as the user types, letter by letter. As each letter is entered, the window is redrawn showing the changes ... ?????? A????? AD???? ADD??? ADDI?? ADDIN? ADDING When all the ? are gone, the user's input is compared to a hidden word. Looks straitforward - until you try implementing it! This is all in the canvas area which fills the window. |
| ||
Ok, that's not really what you were asking for initially. You'll pretty much have to create your own input routine, keep track of which digit the user types, and you can then use the first routine to replace the '?' at that position with the digit that they typed in. (slightly more complicated, since you should also handle things like backspace where someone undoes their last entry) |
| ||
Graphics 500,500,0,2 mystring$="" mymask$="?????" Repeat Cls mystring=rinput(mystring) outputstr$="" For i=1 To Len(mymask) If Len(mystring)>=i Then outputstr=outputstr+Mid(mystring,i,1) Else outputstr=outputstr + "?" EndIf Next Text 0,0,outputstr Flip Until KeyDown(1) End ;from code archives Function rInput$(aString$) value = GetKey() length = Len(aString$) If value = 13 Then Goto ende If value = 8 Then value = 0 If length > 0 Then aString$ = Left$(aString,Length-1) EndIf If value = 0 Then Goto ende If value>0 And value<7 Or value>26 And value<32 Or value=9 Then Goto ende aString$=aString$ + Chr$(value) .ende Return aString$ End Function like this? |
| ||
So was that what you wanted? |
| ||
WOW, thank you Matty, That was great! |