
-----------------------------------
uknowhoiam
Wed Dec 17, 2008 4:30 pm

Replacing a word with an asterix
-----------------------------------
Here's my question that i have to answer .. 

Write a program that asks the user to input a word and a letter to search for in that word.  Search for the letter in the word. If it is found, replace it with an asterix ?*? and print the resulting string. If not found, notify the user.  Your output should look like this:

				Enter a word: Daddy
				Enter a letter to search for: g
				Daddy does not have the letter g in it.
				~or~
				Enter a word: Hello
				Enter a letter to search for: l
				He**o

I dont know how to replace a word with an asterix.. i've tried ' letter := * ' but i get an error
can someone please help

-----------------------------------
Tony
Wed Dec 17, 2008 4:48 pm

RE:Replacing a word with an asterix
-----------------------------------
what is this "letter" variable, and what is the value of * ?

Programming via throwing random things at the source is less forgiving than throwing random words at a text document, and hoping than an essay on your English class' book will come out.

Without replacing anything, how would you simply isolate a single letter out of a word?

-----------------------------------
uknowhoiam
Wed Dec 17, 2008 5:06 pm

RE:Replacing a word with an asterix
-----------------------------------
letter is entered by the user

this is what i have done so far..
var word : string
var letter : string

put "Enter a word: " ..
get word
put "Enter a letter: " ..
loop
    get letter
    if index (word, letter) not= 0 then    
    letter := 
    put "Your new word is ", 
        exit
    else
        put word, " does not contain the letter ", letter
    end if
end loop

i dont know what to put after 'letter :=' and after the incomplete put command

please help


Mod Edit: Remember to use syntax tags! Thanks :) [syntax="Turing"]Code Here[/syntax]

-----------------------------------
Tony
Wed Dec 17, 2008 5:10 pm

RE:Replacing a word with an asterix
-----------------------------------
word and letter are two separate variables. If you change anything in letter (letter := ...) it will not have any affect on the word variable.

You might find a tutorial on [url=http://compsci.ca/v3/viewtopic.php?t=8229]String Manipulation to be useful.

-----------------------------------
uknowhoiam
Thu Dec 18, 2008 8:22 pm

RE:Replacing a word with an asterix
-----------------------------------
i got it to work : ).... thx for your help tony

i read the string manipulation, but it didnt really help me

but w/e i got it to work :)

-----------------------------------
Tony
Thu Dec 18, 2008 8:26 pm

RE:Replacing a word with an asterix
-----------------------------------
How'd you manage to do that?

-----------------------------------
uknowhoiam
Fri Dec 19, 2008 3:49 pm

RE:Replacing a word with an asterix
-----------------------------------
this is my code

var letter : string

put "Enter a word: " ..
get word
put "Enter a letter: " ..
 letter
loop
    get letter
    %if index not = 0 then..
    if index (word, letter) not= 0 then
        
        loop
            word := word (1 .. index (word, letter) - 1) + "*" + word (index (word, letter) + 1 .. *)
            
            exit when index (word, letter) = 0
        end loop
        exit
    else
        put word, " does not contain the letter ", letter
    end if
end loop

put word


word:= word (1..index(word,letter) - 1) + "*" + word (index (word,letter) + 1 .. *)  is the 'equation' that made this work

Mod Edit: Remember to use syntax tags![syntax="Turing"]Code Here[/syntax]

-----------------------------------
dc116
Fri Dec 19, 2008 5:25 pm

RE:Replacing a word with an asterix
-----------------------------------
Remember that you have to declare all the variables first.
