Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 39 / 68

Normalizing strings (strip and case)

This lesson covers normalizing strings in Julia, with the aim of comparing text that is written inconsistently.

Text typed by a user tends to carry stray whitespace at the ends and inconsistent capitalisation. Stripping it with strip() and unifying the case with lowercase() is called normalization.

The sample code runs lowercase(strip(s)) inside a normalize() function, stripping the surrounding whitespace and then lower-casing. Two strings that look different — " Hello World " and "hello world" — compare as the same once normalized.

A common early stumble is comparing without this step. Two strings that look identical to a person can come back false, which makes for a bug that is hard to track down.

In professional work, normalization is a basic technique that turns up constantly — validating input, handling logins.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)