D Characters - D Programming Language

What are D Characters?

Characters are the building blocks of strings. Any symbol of a writing system is known as a character: letters of alphabets, numerals, punctuation marks, the space character, etc. Confusingly, the building blocks of characters themselves are called characters as properly.

The integer cost of the lowercase a is 97 and the integer value of the numeral 1 is 49. These values had been assigned simply by conventions whilst the ASCII table has been designed.

Following table gives you details about standard character types with storage sizes and its reason.

Characters are represented via the char type that could hold best 256 distinct values. In case you are acquainted with the char kind from different languages, you could already recognize that it isn't huge sufficient to guide the symbols of many writing systems.

Type

Storage size

Purpose

char

1 byte

UTF-8 code unit

wchar

2 bytes

UTF-16 code unit

dchar

4 bytes

UTF-32 code unit and Unicode code point

Some useful character functions are listed below

  • isLower: is a lowercase character?
  • isUpper: is an uppercase character?
  • isAlpha: is a Unicode alphanumeric character (generally, a letter or a numeral)?
  • isWhite: is a whitespace character?
  • toLower: produces the lowercase of the given character
  • toUpper: produces the uppercase of the given character

When we run the above program, we will get the following output

Reading Characters

We can read characters using readf as shown below.

Since D programming support unicode, in order to read unicode characters, we need to read twice and write twice to get the expected result. This don't work on the online compiler. The example is shown below.

When we run the above program, we will get the following output

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

D Programming Language Topics