Computer Science Canada

can you delete a part of a string?

Author:  junkpro11 [ Sat May 29, 2004 8:48 pm ]
Post subject:  can you delete a part of a string?

i want to getch sth then add all the strings together, and if the backspace is pressed, i want to delete watever i recently getch

this is my code
code:

loop
            count := count + 1
           
            locate (10, 30 + count)
            getch (input)
           
            exit when input= chr (10)
            put "-"..
            if input not=chr(10) and input not=chr (8) then
            guess:= guess + input
            end if
            if input = chr (8) then
                locate (10, 30 + count - 1)
                put ""
                count := count - 2
                 
            elsif input = chr (10) then %enter key
                Music.PlayFile ("select.wav")
            else
                guess:=guess
            end if
            end loop


Author:  Paul [ Sat May 29, 2004 8:53 pm ]
Post subject: 

its like this, you have a string
say
code:

var word: string:="hello"

then if backspace is pressed, then make the word = to this
code:

if backspace is pressed then
word:=word(1..(length(word)-1))
end if
cls
put word

Author:  junkpro11 [ Sat May 29, 2004 9:04 pm ]
Post subject: 

thanks!

Author:  Paul [ Sat May 29, 2004 9:07 pm ]
Post subject: 

lets say u have a string containing "abcde"
the first letter of the string, or in the code word(1) is a
word(2) is b and so on.
The code, when u press backspace
it makes the value of the word equal to from the first letter of ur string to the second last letter
so if you have abcde
the code would reduce it to
abcd, when u press backspace
ofcourse it would crash when you have nothing left and u still press backspace... so u have to restrict that.
length(word) just finds the length
and word:=word(1..(length(word)-1))
is basically, word is equal to word from letter one to the second last letter.

Author:  junkpro11 [ Sat May 29, 2004 9:35 pm ]
Post subject: 

thanks....i experimented a bit and kinda understood the code. u cleared things up though..

thanks!


: