The C# char
type is a 16 bit quantity to represent the smallest addressable components of text.
Multiple char
s can comprise a string such as "word"
or char
s can be
processed independently. Their literals have single quotes e.g. 'A'
.
C# char
s support UTF-16 Unicode encoding so in addition to the latin character set
pretty much all the writing systems used in the world can be represented,
e.g. the Greek letter 'β'
.
There are many builtin library methods to inspect and manipulate char
s. These
can be found as static methods of the System.Char
class.
char
s are sometimes used in conjunction with a StringBuilder
object.
This object has methods that allow a string to be constructed
character by character and manipulated. At the end of the process
ToString
can be called on it to output a complete string.
In this exercise, you will implement a partial set of utility routines to help a developer clean up identifier names.
In the 5 tasks you will gradually build up the routine Clean
.
A valid identifier comprises zero or more letters and underscores.
In all cases, the input string is guaranteed to be non-null.
If an empty string is passed to the Clean
function, an empty string should be returned.
Note that the caller should avoid calling the routine Clean
with an empty identifier since such identifiers are ineffectual.
Implement the (static) Identifier.Clean()
method to replace any spaces with underscores.
This also applies to leading and trailing spaces.
Identifier.Clean("my Id");
// => "my___Id"
Modify the (static) Identifier.Clean()
method to replace control characters with the upper case string "CTRL"
.
Identifier.Clean("my\0Id");
// => "myCTRLId",
Modify the (static) Identifier.Clean()
method to convert kebab-case to camelCase.
Identifier.Clean("à -ḃç");
// => "à Ḃç"
Modify the (static) Identifier.Clean()
method to omit any characters that are not letters.
Identifier.Clean("1😀2😀3😀");
// => ""
Modify the (static) Identifier.Clean()
method to omit any Greek letters in the range 'α' to 'ω'.
Identifier.Clean("MyΟβιεγτFinder");
// => "MyΟFinder"
Sign up to Exercism to learn and master C# with 62 concepts, 170 exercises, and real human mentoring, all for free.