Author |
Message |
uknowhoiam
|
Posted: Wed Dec 17, 2008 4:30 pm Post subject: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Dec 17, 2008 4:48 pm Post subject: 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? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
uknowhoiam
|
Posted: Wed Dec 17, 2008 5:06 pm Post subject: RE:Replacing a word with an asterix |
|
|
letter is entered by the user
this is what i have done so far..
Turing: | 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 code: | [syntax="Turing"]Code Here[/syntax] |
|
|
|
|
|
|
Tony
|
Posted: Wed Dec 17, 2008 5:10 pm Post subject: 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 String Manipulation to be useful. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
uknowhoiam
|
Posted: Thu Dec 18, 2008 8:22 pm Post subject: 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
|
|
|
|
|
uknowhoiam
|
Posted: Fri Dec 19, 2008 3:49 pm Post subject: RE:Replacing a word with an asterix |
|
|
this is my code
Turing: |
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
|
Turing: | 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! code: | [syntax="Turing"]Code Here[/syntax] |
|
|
|
|
|
|
dc116
|
Posted: Fri Dec 19, 2008 5:25 pm Post subject: RE:Replacing a word with an asterix |
|
|
Remember that you have to declare all the variables first. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|