help with the index!!
Author |
Message |
DBZ
|
Posted: Thu Dec 25, 2003 7:25 pm Post subject: help with the index!! |
|
|
Guys, i need help with the following program! U see the program is suppose to replace the letter in a word with another letter. This program i have made so far, only replaces one letter in the word if there are two same letters. For example, If i have entered the word "Banana" and then if i have enetered the patern "a" then the replacement pattern"o". it is suppose to output he word "Bonono". but it doesn't do that! please help! thanx! Please enter ur suggestions in the program and repost it here!
Here is the program:
var word, pattern,replacement:string
var pos:int
put"Enter the word: "..
get word
put"Enter the pattern: "..
get pattern
put "Enter replacement: "..
get replacement
word:=word(1..(index(word,pattern)-1))+ replacement+word((index(word,pattern)+1)..*)
put word |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Dec 25, 2003 7:31 pm Post subject: (No subject) |
|
|
oh, boo hoo
that's because you replace only once. You need to have that in the loop. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
DBZ
|
Posted: Thu Dec 25, 2003 7:36 pm Post subject: (No subject) |
|
|
Tony, i don't get it! could u please be more specific? thanx! |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Fri Dec 26, 2003 1:42 am Post subject: (No subject) |
|
|
you see how you got this
index + replace + index ?
well as you said it yourself, what if replace would have to be in more place then one (2+ letters/patterns). That would have to make it
index + replace + index + replace + index...
but since you dont know what crazy thing the user will enter, you'd have to make a loop that follows in that pattern. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|