# strings problem

• November 18th, 2012, 11:28 PM
switch
strings problem
HI, I have a problem to resolve and I don't know how to do it.
The problem goes as follow: I have two strings. Each string is a sequence of letter.
First, I have to return the sequence of letter representing the first string where is deleted the common prefix to both strings.
For example: if I have the strings abcde and abcgh, it returns de, where abc is the common prefix.
Second, I have to return the sequence of letter obtained by deleting all the letters that occurs more than one and keep all the first occurrence of these letters.
For example: abddeggh would equal abdegh
Third,I have to return the sequence of letter by keeping only the first occurrence of the letters in a first sequence of letter and delete all the letters that appear in a second sequence of letters.
For example: asdfgghh and uioasf, would equal dgh.

Can I get help to resolve these three problems please?
• November 19th, 2012, 12:10 PM
mperemsky
Re: strings problem
1. loop though both words at the same time. Once you encounter a letter that is different print out the substring of the first word.
2. Loop through the string. Remember the last character. If the current character is the same as the last character do not print it.
3. Easiest way, loop through each character of the first work. Loop through the second word, if the character appears do not print it.
• November 19th, 2012, 04:16 PM
switch
Re: strings problem
Quote:

Originally Posted by mperemsky
1. loop though both words at the same time. Once you encounter a letter that is different print out the substring of the first word.
2. Loop through the string. Remember the last character. If the current character is the same as the last character do not print it.
3. Easiest way, loop through each character of the first work. Loop through the second word, if the character appears do not print it.

In 2, how do i remember the last character in a loop.
In 1, how do I quit the loop after substring the first word

Thanks for your help by the way