2017년 5월 4일 목요일

Can you Remove Double Letters?


In the blocks, when you press button, the Label text is replaced with whatever the user typed in TextBox. Also all the Vowels are removed.
Is it possible to also remove any DOUBLE letters? Example: if user typed "APPLE", I would want it to return as "APLE". With Vowels gone it should only return, "PL"
Make sense?


--
segment PP
replacement P      will take one of the Ps away

--
Hey thanks for the reply. That only seems to work if the Ps are next to each other. I am thinkin more like, Take away any of the same letters in a sentence. I should also say, Apple was just an example. Ideally I want ANY double of a letter to be removed from a sentence. No set letter, just any double of a letter needs to go. lol

--
A different way to attack this would be to build up a second (output) string from empty,
walking through the input string letter by letter, and for each letter,
skip it if it's a vowel or if it's already in your output string,
otherwise JOIN it onto the end of your output string.

--
Heya Abraham thank you for your input. I'm not exactly sure what you mean, Today is my first day using App Inventor. Is it possible you could screenshot a very simple example of what you mean? All I need is a starting point, not sure how to set it uo tho : )

--
I'm not really sure what you mean by "Skip" thats basically my issue, I dont know what would cause it to skip or remove letters.

--
See chapter 19 here http://www.appinventor.org/book2  it may help...also, the entire Inventor's Manual can be read in about an hour.  This  book is one of the best introductions to AI Blocks anywhere.

--
I tried this, but it only gathers one letter instead of both. 


--
Here's the algorithm in a C-like pseudocode...

set global vowels = 'aeiou'
set global another = empty string
for i = 1 to length(input_string) by 1
   set local variable L = letter at input_string position i
   if AND(not(contains(vowels,L)),not(contains(another,L)) // not a vowel or already in another
      then set another = JOIN(another,L)
end for i

// another contains all  consonants of input_string

P.S.  This can be made even shorter using DeMorgan's Law and a JOIN.

 --

How do you delete duplicate letters in a string?


I'm trying to take a string and delete duplicate letters in said string. My teacher can't figure it out either, and suggested I try posting here. There was another (old) topic that was asking pretty much the same thing, but it never got solved (or if it did, I wasn't able to figure out how to translate the last reply's pseudo code into the blocks format).

--
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

-- 
That's pretty easy!

Check out in Thunkable community here:

use for each loop and add items to list from string, also check if it exists in the list you are putting into before adding. This way you will have a list of unique characters.

See also:
Adding up specific words in text string

--
You have to build up a new variable from empty a letter at a time from the input string.

Use a for each number from 1 to length(inputString) by 1 loop:

outputString = empty string
for each number from 1 to length(inputString) by 1 
set global nextLetter to segment(inputString at pos number length 1)
If not(outputString contains nextLetter) THEN
   set outputString to JOIN(outputStringnextLetter)
end for each number

-- 
By relevant blocks, do you mean my variables and my components? I'll upload screenshots in my next replies, thanks.

-- 
I tried to replicate your suggestion in the blocks editor like so:


I couldn't figure out what you meant by "end for each number" and building up variables from an empty letter at a time, so I doubt I got everything. I'm a visual learner, so if you gave me a screenshot with an example to learn from, that would help me a lot more, thanks.

-- 
It occurred to me that "duplicate letters" is ambiguous.

For example, if the input word is "Mississippi",
should the output be "Misp" or should it be "Misisipi" ?

In other words, do you only want to delete consecutive duplicates?

-- 
I meant to delete all duplicate letters, so in your example, would be "Misp". Your suggestion worked! (I had screenshotted what I tried doing following Pavitra's advice instead of yours) I guess I did it right this time, because last time I tried yours it didn't work but now it does! I appreciate all your help.

Here's my resulting blocks:
 (Your reply didn't show up in this thread when it showed up in my gmail inbox, so I assumed it was an email, and replied with an email... bluh. I don't use forums so I'm only learning how to use one right now.)

--
Thanks for posting the answer.

By the way, the alternate question, deleting consecutive duplicates,
is close but a bit harder, having to check for text with length < 2.

-- 
A little optimization and formatted as a procedure.
--