String case: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(Replaced "toLower" with "toLowerAscii", "toUpper" with "toUpperAscii" and "capitalize" with "capitalizeAscii". Added a general comment.)
Line 1,838: Line 1,838:


=={{header|Nim}}==
=={{header|Nim}}==
In the following example, we use the ASCII version of the procedures to convert to lower case, to convert to upper case or to normalize. In module “unicode” there exists also three procedures "toLower", "toUpper" and "title" which can do the same thing for UTF-8 encoded strings.

<lang nim>import strutils
<lang nim>import strutils


var s: string = "alphaBETA_123"
var s: string = "alphaBETA_123"
echo s," as upper case: ", toUpper(s)
echo s, " as upper case: ", toUpperAscii(s)
echo s," as lower case: ", toLower(s)
echo s, " as lower case: ", toLowerAscii(s)
echo s," as Capitalized: ", capitalize(s)
echo s, " as capitalized: ", capitalizeAscii(s)
echo s," as normal case: ", normalize(s) # remove underscores, toLower</lang>
echo s, " as normal case: ", normalize(s) # to lower case without underscores.</lang>
{{out}}
{{out}}

<pre>alphaBETA_123 as upper case: ALPHABETA_123
<pre>alphaBETA_123 as upper case: ALPHABETA_123
alphaBETA_123 as lower case: alphabeta_123
alphaBETA_123 as lower case: alphabeta_123
alphaBETA_123 as Capitalized: AlphaBETA_123
alphaBETA_123 as capitalized: AlphaBETA_123
alphaBETA_123 as normal case: alphabeta123</pre>
alphaBETA_123 as normal case: alphabeta123</pre>