how to change a letter in a string

BlitzPlus Forums/BlitzPlus Programming/how to change a letter in a string

julianbury(Posted 2009) [#1]
I need to overwrite a letter in position X within a string.

Can anyone point me to the obvious solution, please?

(-_-)


xlsior(Posted 2009) [#2]
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 '@'



julianbury(Posted 2009) [#3]
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.


xlsior(Posted 2009) [#4]
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)


Matty(Posted 2009) [#5]
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?


Matty(Posted 2009) [#6]
So was that what you wanted?


julianbury(Posted 2009) [#7]
WOW, thank you Matty,
That was great!