Skip to first unread message

Claepots

unread,
May 2, 2017, 2:20:23 PM5/2/17
to MIT App Inventor Forum
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).

Taifun

unread,
May 2, 2017, 2:27:04 PM5/2/17
to MIT App Inventor Forum
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.

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Pavitra

unread,
May 2, 2017, 2:35:33 PM5/2/17
to MIT App Inventor Forum
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:
http://community.thunkable.com/t/adding-up-specific-words-in-text-string/2423/18?u=pavi2410

Abraham Getzler

unread,
May 2, 2017, 3:37:55 PM5/2/17
to MIT App Inventor Forum
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(outputString, nextLetter)
end for each number

ABG

Claepots

unread,
May 4, 2017, 1:33:40 PM5/4/17
to MIT App Inventor Forum
By relevant blocks, do you mean my variables and my components? I'll upload screenshots in my next replies, thanks.

-Claepots

Claepots

unread,
May 4, 2017, 1:42:10 PM5/4/17
to mitappinv...@googlegroups.com
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.

- Claepots

EDIT: Oops, uploaded the wrong screenshot. Give me a sec.

Abraham Getzler

unread,
May 4, 2017, 2:05:31 PM5/4/17
to MIT App Inventor Forum
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?

ABG

Claepots

unread,
May 4, 2017, 2:26:46 PM5/4/17
to MIT App Inventor Forum
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.)

- Claepots

Abraham Getzler

unread,
May 4, 2017, 2:39:19 PM5/4/17
to MIT App Inventor Forum
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.

ABG


Italo

unread,
May 4, 2017, 3:55:44 PM5/4/17
to MIT App Inventor Forum
A little optimization and formatted as a procedure.


Reply all
Reply to author
Forward
0 new messages