For today's challenge, you must write a program or function that alternates the case of a string. However, you must ignore non-alphabetic characters. This means that every alphabetic character must have a different case than the preceding and following alphabetic character. This is slightly more complex than uppercasing every other letter for example. If you take a string such as
hello world
and convert every other character to uppercase, you'll get:
hElLo wOrLd
As you can see, the lowercase o
is followed by a lowercase w
. This is invalid. Instead, you must ignore the space, giving us this result:
hElLo WoRlD
All non-alphabetic characters must be left the same. The output can start with upper or lowercase, as long as it consistently alternates. This means the following would also be an acceptable output:
HeLlO wOrLd
Your program should work regardless of the case of the input.
The input string will only ever contain printable ASCII, so you don't have to worry about unprintable characters, newlines or unicode. Your submission can be either a full program or a function, and you may take the input and output in any reasonable format. For example, function arguments/return value, STDIN/STDOUT, reading/writing a file, etc.
Examples:
ASCII -> AsCiI
42 -> 42
#include <iostream> -> #InClUdE <iOsTrEaM>
LEAVE_my_symbols#!#&^%_ALONE!!! -> lEaVe_My_SyMbOlS#!#&^%_aLoNe!!!
PPCG Rocks!!! For realz. -> PpCg RoCkS!!! fOr ReAlZ.
This example will start with lowercase -> tHiS eXaMpLe WiLl StArT wItH lOwErCaSe
This example will start with uppercase -> ThIs ExAmPlE wIlL sTaRt WiTh UpPeRcAsE
A1B2 -> A1b2
Since this is code-golf, standard loopholes apply and the shortest answer in bytes wins!
cowsay
\$\endgroup\$