#4.17 LAB: Remove all non alpha characters

10 messages · Page 1 of 1 (latest)

wary mango
#

Write a program that removes all non alpha characters from the given input.

Ex: If the input is:

-Hello, 1 world$!

twin troutBOT
#

This post has been reserved for your question.

Hey @wary mango! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pseudo pollen
#

you can use a regex

#

[^A-Za-z] will match non-alphabetical characters

#

you can replace all of them using .replaceAll

#

if you are allowed to use regexes

#

if not, ho over all characters, check if it's alphabetical and remove them if they aren't

smoky crypt
#

note: don't loop over the same string you're removing from, that causes issues
best way is to create a new string/stringbuilder from the chars that are alphabetical for a simple approach, or you could use streams and filter if you can use streams