
-----------------------------------
DBZ
Thu Dec 25, 2003 7:25 pm

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

-----------------------------------
Tony
Thu Dec 25, 2003 7:31 pm


-----------------------------------
oh, boo hoo :?

that's because you replace only once. You need to have that in the loop.

-----------------------------------
DBZ
Thu Dec 25, 2003 7:36 pm


-----------------------------------
Tony, i don't get it! could u please be more specific? thanx!

-----------------------------------
Tony
Fri Dec 26, 2003 1:42 am


-----------------------------------
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.
