Can you Remove Double Letters?

41 views
Skip to first unread message

2DG Blog

unread,
Mar 19, 2015, 5:25:26 PM3/19/15
to mitappinv...@googlegroups.com
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?


noVowels.png

SteveJG

unread,
Mar 19, 2015, 5:36:10 PM3/19/15
to mitappinv...@googlegroups.com
segment PP
replacement P      will take one of the Ps away


2DG Blog

unread,
Mar 19, 2015, 5:42:46 PM3/19/15
to mitappinv...@googlegroups.com
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

Abraham Getzler

unread,
Mar 19, 2015, 6:06:49 PM3/19/15
to mitappinv...@googlegroups.com
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.

ABG

2DG Blog

unread,
Mar 19, 2015, 6:35:13 PM3/19/15
to mitappinv...@googlegroups.com
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 : )

2DG Blog

unread,
Mar 19, 2015, 6:57:24 PM3/19/15
to mitappinv...@googlegroups.com
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.

SteveJG

unread,
Mar 19, 2015, 7:56:06 PM3/19/15
to mitappinv...@googlegroups.com
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.

Regards,
Steve
Message has been deleted
Message has been deleted

2DG Blog

unread,
Mar 20, 2015, 8:12:31 AM3/20/15
to mitappinv...@googlegroups.com
I tried this, but it only gathers one letter instead of both. 
remove.png

Abraham Getzler

unread,
Mar 20, 2015, 11:23:09 AM3/20/15
to mitappinv...@googlegroups.com
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

ABG

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

 
Reply all
Reply to author
Forward
0 new messages