Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.ascii

Functions which operate on ASCII characters.
All of the functions in std.ascii accept Unicode characters but effectively ignore them if they're not ASCII. AllisX functions returnfalse for non-ASCII characters, and alltoX functions do nothing to non-ASCII characters.
For functions which operate on Unicode characters, seestd.uni.
CategoryFunctions
ValidationisAlphaisAlphaNumisASCIIisControlisDigitisGraphicalisHexDigitisLowerisOctalDigitisPrintableisPunctuationisUpperisWhite
ConversionstoLowertoUpper
ConstantsdigitsfullHexDigitshexDigitsletterslowercaselowerHexDigitsnewlineoctalDigitsuppercasewhitespace
EnumsControlCharLetterCase

ReferencesASCII Table,Wikipedia

License:
Boost License 1.0.
Authors:
Walter Bright andJonathan M Davis

Sourcestd/ascii.d

immutable stringfullHexDigits;
0 .. 9A .. Fa .. f
immutable stringhexDigits;
0 .. 9A .. F
immutable stringlowerHexDigits;
0 .. 9a .. f
immutable stringdigits;
0 .. 9
immutable stringoctalDigits;
0 .. 7
immutable stringletters;
A .. Za .. z
immutable stringuppercase;
A .. Z
immutable stringlowercase;
a .. z
immutable stringwhitespace;
ASCII whitespace
enumLetterCase: bool;
Letter case specifier.
Examples:
import std.conv : to;writeln(42.to!string(16,LetterCase.upper));// "2A"writeln(42.to!string(16,LetterCase.lower));// "2a"
Examples:
import std.digest.hmac : hmac;import std.digest : toHexString;import std.digest.sha : SHA1;import std.string : representation;const sha1HMAC ="A very long phrase".representation    .hmac!SHA1("secret".representation)    .toHexString!(LetterCase.lower);writeln(sha1HMAC);// "49f2073c7bf58577e8c9ae59fe8cfd37c9ab94e5"
upper
Upper case letters
lower
Lower case letters
enumControlChar: char;
All control characters in the ASCII table (source).
Examples:
import std.algorithm.comparison, std.algorithm.searching, std.range, std.traits;// Because all ASCII characters fit in char, so do thesestaticassert(ControlChar.ack.sizeof == 1);// All control characters except del are in row starting from 0staticassert(EnumMembers!ControlChar.only.until(ControlChar.del).equal(iota(32)));staticassert(ControlChar.nul == '\0');staticassert(ControlChar.bel == '\a');staticassert(ControlChar.bs  == '\b');staticassert(ControlChar.ff  == '\f');staticassert(ControlChar.lf  == '\n');staticassert(ControlChar.cr  == '\r');staticassert(ControlChar.tab == '\t');staticassert(ControlChar.vt  == '\v');
Examples:
import std.conv;//Control character table can be used in place of hexcodes.with (ControlChar)assert(text("Phobos", us,"Deimos", us,"Tango", rs) =="Phobos\x1FDeimos\x1FTango\x1E");
nul
Null
soh
Start of heading
stx
Start of text
etx
End of text
eot
End of transmission
enq
Enquiry
ack
Acknowledge
bel
Bell
bs
Backspace
tab
Horizontal tab
lf
NL line feed, new line
vt
Vertical tab
ff
NP form feed, new page
cr
Carriage return
so
Shift out
si
Shift in
dle
Data link escape
dc1
Device control 1
dc2
Device control 2
dc3
Device control 3
dc4
Device control 4
nak
Negative acknowledge
syn
Synchronous idle
etb
End of transmission block
can
Cancel
em
End of medium
sub
Substitute
esc
Escape
fs
File separator
gs
Group separator
rs
Record separator
us
Unit separator
del
Delete
immutable stringnewline;
Newline sequence for this system.
pure nothrow @nogc @safe boolisAlphaNum(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a letter or a number (0 .. 9, a .. z, A .. Z).
Examples:
assert(isAlphaNum('A'));assert(isAlphaNum('1'));assert(!isAlphaNum('#'));// N.B.: does not return true for non-ASCII Unicode alphanumerics:assert(!isAlphaNum('á'));
pure nothrow @nogc @safe boolisAlpha(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is an ASCII letter (A .. Z, a .. z).
Examples:
assert(isAlpha('A'));assert(!isAlpha('1'));assert(!isAlpha('#'));// N.B.: does not return true for non-ASCII Unicode alphabetic characters:assert(!isAlpha('á'));
pure nothrow @nogc @safe boolisLower(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a lowercase ASCII letter (a .. z).
Examples:
assert(isLower('a'));assert(!isLower('A'));assert(!isLower('#'));// N.B.: does not return true for non-ASCII Unicode lowercase lettersassert(!isLower('á'));assert(!isLower('Á'));
pure nothrow @nogc @safe boolisUpper(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is an uppercase ASCII letter (A .. Z).
Examples:
assert(isUpper('A'));assert(!isUpper('a'));assert(!isUpper('#'));// N.B.: does not return true for non-ASCII Unicode uppercase lettersassert(!isUpper('á'));assert(!isUpper('Á'));
pure nothrow @nogc @safe boolisDigit(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a digit (0 .. 9).
Examples:
assert(isDigit('3'));assert(isDigit('8'));assert(!isDigit('B'));assert(!isDigit('#'));// N.B.: does not return true for non-ASCII Unicode numbersassert(!isDigit('0'));// full-width digit zero (U+FF10)assert(!isDigit('4'));// full-width digit four (U+FF14)
pure nothrow @nogc @safe boolisOctalDigit(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a digit in base 8 (0 .. 7).
Examples:
assert(isOctalDigit('0'));assert(isOctalDigit('7'));assert(!isOctalDigit('8'));assert(!isOctalDigit('A'));assert(!isOctalDigit('#'));
pure nothrow @nogc @safe boolisHexDigit(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a digit in base 16 (0 .. 9, A .. F, a .. f).
Examples:
assert(isHexDigit('0'));assert(isHexDigit('A'));assert(isHexDigit('f'));// lowercase hex digits are acceptedassert(!isHexDigit('g'));assert(!isHexDigit('G'));assert(!isHexDigit('#'));
pure nothrow @nogc @safe boolisWhite(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whether or notc is a whitespace character. That includes the space, tab, vertical tab, form feed, carriage return, and linefeed characters.
Examples:
assert(isWhite(' '));assert(isWhite('\t'));assert(isWhite('\n'));assert(!isWhite('1'));assert(!isWhite('a'));assert(!isWhite('#'));// N.B.: Does not return true for non-ASCII Unicode whitespace characters.staticimport std.uni;assert(std.uni.isWhite('\u00A0'));assert(!isWhite('\u00A0'));// std.ascii.isWhite
pure nothrow @nogc @safe boolisControl(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whetherc is a control character.
Examples:
assert(isControl('\0'));assert(isControl('\022'));assert(isControl('\n'));// newline is both whitespace and controlassert(!isControl(' '));assert(!isControl('1'));assert(!isControl('a'));assert(!isControl('#'));// N.B.: non-ASCII Unicode control characters are not recognized:assert(!isControl('\u0080'));assert(!isControl('\u2028'));assert(!isControl('\u2029'));
pure nothrow @nogc @safe boolisPunctuation(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whether or notc is a punctuation character. That includes all ASCII characters which are not control characters, letters, digits, or whitespace.
Examples:
assert(isPunctuation('.'));assert(isPunctuation(','));assert(isPunctuation(':'));assert(isPunctuation('!'));assert(isPunctuation('#'));assert(isPunctuation('~'));assert(isPunctuation('+'));assert(isPunctuation('_'));assert(!isPunctuation('1'));assert(!isPunctuation('a'));assert(!isPunctuation(' '));assert(!isPunctuation('\n'));assert(!isPunctuation('\0'));// N.B.: Non-ASCII Unicode punctuation characters are not recognized.assert(!isPunctuation('\u2012'));// (U+2012 = en-dash)
pure nothrow @nogc @safe boolisGraphical(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whether or notc is a printable character other than the space character.
Examples:
assert(isGraphical('1'));assert(isGraphical('a'));assert(isGraphical('#'));assert(!isGraphical(' '));// whitespace is not graphicalassert(!isGraphical('\n'));assert(!isGraphical('\0'));// N.B.: Unicode graphical characters are not regarded as such.assert(!isGraphical('á'));
pure nothrow @nogc @safe boolisPrintable(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whether or notc is a printable character - including the space character.
Examples:
assert(isPrintable(' '));// whitespace is printableassert(isPrintable('1'));assert(isPrintable('a'));assert(isPrintable('#'));assert(!isPrintable('\0'));// control characters are not printable// N.B.: Printable non-ASCII Unicode characters are not recognized.assert(!isPrintable('á'));
pure nothrow @nogc @safe boolisASCII(dcharc);
Parameters:
dcharcThe character to test.
Returns:
Whether or notc is in the ASCII character set - i.e. in the range 0 .. 0x7F.
Examples:
assert(isASCII('a'));assert(!isASCII('á'));
autotoLower(C)(Cc)
if (is(C : dchar));
Converts an ASCII letter to lowercase.
Parameters:
CcA character of any type that implicitly converts todchar. In the case where it's a built-in type, or an enum of a built-in type,Unqual!(OriginalType!C) is returned, whereas if it's a user-defined type,dchar is returned.
Returns:
The corresponding lowercase letter, ifc is an uppercase ASCII character, otherwisec itself.
Examples:
writeln(toLower('a'));// 'a'writeln(toLower('A'));// 'a'writeln(toLower('#'));// '#'// N.B.: Non-ASCII Unicode uppercase letters are not converted.writeln(toLower('Á'));// 'Á'
autotoUpper(C)(Cc)
if (is(C : dchar));
Converts an ASCII letter to uppercase.
Parameters:
CcAny type which implicitly converts todchar. In the case where it's a built-in type, or an enum of a built-in type,Unqual!(OriginalType!C) is returned, whereas if it's a user-defined type,dchar is returned.
Returns:
The corresponding uppercase letter, ifc is a lowercase ASCII character, otherwisec itself.
Examples:
writeln(toUpper('a'));// 'A'writeln(toUpper('A'));// 'A'writeln(toUpper('#'));// '#'// N.B.: Non-ASCII Unicode lowercase letters are not converted.writeln(toUpper('á'));// 'á'
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 00:06:56 2026

[8]ページ先頭

©2009-2026 Movatter.jp