英語版
このページの英語版を見る
std.string
文字列を扱う関数。
| カテゴリー | 関数 |
|---|---|
| Searching | column indexOf indexOfAny indexOfNeither lastIndexOf lastIndexOfAny lastIndexOfNeither |
| Comparison | isNumeric |
| Mutation | capitalize |
| Pruning and Filling | center chomp chompPrefix chop detabber detab entab entabber leftJustify outdent rightJustify strip stripLeft stripRight wrap |
| Substitution | abbrev soundex soundexer succ tr translate |
| Miscellaneous | assumeUTF fromStringz lineSplitter representation splitLines toStringz |
string型、wstring 型、dstring 型のオブジェクトは "値 "型である。
であり、要素ごとに変異させることはできない。文字列を構築する際に変異を使用するには、 、 、 を使用する。
char[] wchar[] dchar[]型は、望ましくないエイリアシングを示さないため、望ましい。xxxstring
型が望ましいのは、望ましくないエイリアシングが発生しないためである。
コードがより堅牢になる。
以下の関数は一般にインポートされている:
| モジュール | 関数 |
|---|---|
| 一般にインポートされた関数 | |
| 標準アルゴリズム | cmp count endsWith startsWith |
| 標準配列 | join replace replaceInPlace split empty |
| std.format関数 | format sformat |
| std.uni関数 | icmp toLower toLowerInPlace toUpper toUpperInPlace |
See Also:
- std.algorithmそして std.range 汎用レンジアルゴリズム
- std.ascii ASCII文字列を扱う関数用
- std.uni ユニコード文字列を扱う関数用
License:
Authors:
ソース std/string.d
- class
StringException: object.Exception; - std.string関数のエラー時にスローされる例外。Examples:
import std.exception : assertThrown; auto bad = " a\n\tb\n c"; assertThrown!StringException(bad.outdent);
- pure nothrow @nogc @system inout(Char)[]
fromStringz(Char)(return scope inout(Char)*cString)
if (isSomeChar!Char);
pure nothrow @nogc @safe inout(Char)[]fromStringz(Char)(return scope inout(Char)[]cString)
if (isSomeChar!Char); - Parameters:
inout(Char)* cStringヌル終端のC言語のスタイル文字列。 Returns:同じ文字列を参照するchar 、wchar 、dchar のD言語のスタイル配列。 のD型配列。返される配列は、入力と同じ型修飾子を保持する。 重要注釈:返される配列は、元のバッファのスライスである。 元のデータは変更されず、コピーもされない。Examples:writeln(fromStringz("foo\0"c.ptr)); // "foo"c writeln(fromStringz("foo\0"w.ptr)); // "foo"w writeln(fromStringz("foo\0"d.ptr)); // "foo"d writeln(fromStringz("福\0"c.ptr)); // "福"c writeln(fromStringz("福\0"w.ptr)); // "福"w writeln(fromStringz("福\0"d.ptr)); // "福"d
Examples:struct C { char[32] name; } writeln(C("foo\0"c).name.fromStringz()); // "foo"c struct W { wchar[32] name; } writeln(W("foo\0"w).name.fromStringz()); // "foo"w struct D { dchar[32] name; } writeln(D("foo\0"d).name.fromStringz()); // "foo"d
- pure nothrow @trusted immutable(char)*
toStringz(scope const(char)[]s); - Parameters:
const(char)[] sD言語のスタイル。 Returns:C言語のヌル終端文字列。s.sに相当するCスタイルのヌル終端文字列は、'\0''を埋め込んではならない。 '\0' を文字列の終わりとして扱うからである。もしs.emptyが true であれば、'\0' のみを含む文字列が返される。 重要釈:C関数にchar* 。 関数が何らかの理由でその関数を保持する場合、Dコードでその関数への参照を保持していることを確認すること。 への参照を保持していることを確認すること。そうしないと、ガベージ・コレクション・サイクルの間に無効になってしまい ガベージコレクションサイクル中に無効となり、Cコードがそれを使おうとしたときに厄介なバグを引き起こす可能性がある。 という厄介なバグを引き起こす可能性がある。Examples:import core.stdc.string : strlen; import std.conv : to; auto p = toStringz("foo"); writeln(strlen(p)); // 3 const(char)[] foo = "abbzxyzzy"; p = toStringz(foo[3 .. 5]); writeln(strlen(p)); // 2 string test = ""; p = toStringz(test); writeln(*p); // 0 test = "\0"; p = toStringz(test); writeln(*p); // 0 test = "foo\0"; p = toStringz(test); assert(p[0] == 'f' && p[1] == 'o' && p[2] == 'o' && p[3] == 0); const string test2 = ""; p = toStringz(test2); writeln(*p); // 0 assert(toStringz([]) is toStringz(""));
- alias
CaseSensitive= std.typecons.Flag!"caseSensitive".Flag; - 検索で大文字と小文字を区別するかどうかを示すフラグ。
- ptrdiff_t
indexOf(Range)(Ranges, dcharc, CaseSensitivecs= Yes.caseSensitive)
if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range);
ptrdiff_tindexOf(C)(scope const(C)[]s, dcharc, CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!C);
ptrdiff_tindexOf(Range)(Ranges, dcharc, size_tstartIdx, CaseSensitivecs= Yes.caseSensitive)
if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range);
ptrdiff_tindexOf(C)(scope const(C)[]s, dcharc, size_tstartIdx, CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!C); - 範囲内の文字を検索する。Parameters:
Range s正しいUTFフォーマットで検索する文字の文字列またはInputRange dchar c検索する文字 size_t startIdx整形式コードポイントへの開始インデックス CaseSensitive csYes.caseSensitive またはNo.caseSensitive Returns:が最初に出現するcである。sの最初の出現位置のインデックスである。 が最初に現れるインデックスである。startIdx.もしcが見つからない場合は、-1 が返される。 もしcが見つかった場合、返されるインデックスの値は少なくともstartIdx. パラメータが有効なUTFでない場合でも、結果は[-1 . s.length]の範囲に入るが、そうでなければ信頼できない。Throws:もしstartIdxで始まるシーケンスが で始まるシーケンスが正しく形成されたコードポイントを表していない場合 std.utf.UTFExceptionがスローされる。See Also:Examples:import std.typecons : No; string s = "Hello World"; writeln(indexOf(s, 'W')); // 6 writeln(indexOf(s, 'Z')); // -1 writeln(indexOf(s, 'w', No.caseSensitive)); // 6
Examples:import std.typecons : No; string s = "Hello World"; writeln(indexOf(s, 'W', 4)); // 6 writeln(indexOf(s, 'Z', 100)); // -1 writeln(indexOf(s, 'w', 3, No.caseSensitive)); // 6
- ptrdiff_t
indexOf(Range, Char)(Ranges, const(Char)[]sub)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char);
ptrdiff_tindexOf(Range, Char)(Ranges, const(Char)[]sub, in CaseSensitivecs)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char);
@safe ptrdiff_tindexOf(Char1, Char2)(const(Char1)[]s, const(Char2)[]sub, in size_tstartIdx)
if (isSomeChar!Char1 && isSomeChar!Char2);
@safe ptrdiff_tindexOf(Char1, Char2)(const(Char1)[]s, const(Char2)[]sub, in size_tstartIdx, in CaseSensitivecs)
if (isSomeChar!Char1 && isSomeChar!Char2); - の部分文字列を検索する。
s.Parameters:Range s文字列またはForwardRangeの文字列を正しいUTF形式で検索する。 const(Char)[] sub検索する部分文字列 size_t startIdx検索を開始する s のインデックス CaseSensitive csYes.caseSensitive (デフォルト) またはNo.caseSensitive Returns:が最初に現れるsubのsの最初の出現位置のインデックスである。 が最初に現れるインデックスである。startIdx.もしsubが見つからない場合は が見つからない場合は、-1 が返される。 引数が有効なUTFでない場合でも、結果は[-1 . s.length]の範囲に入るが、それ以外は信頼できない。 もしsubが見つかった場合、返されるインデックスの値は少なくともstartIdx.Throws:もしstartIdxで始まるシーケンスが で始まるシーケンスが正しく形成されたコードポイントを表していない場合 std.utf.UTFExceptionがスローされる。Bugs:大文字小文字を区別しない文字列では動作しない。 towerとtoupperのマッピングが1:1でない場合、大文字小文字を区別しない文字列では動作しない。Examples:import std.typecons : No; string s = "Hello World"; writeln(indexOf(s, "Wo", 4)); // 6 writeln(indexOf(s, "Zo", 100)); // -1 writeln(indexOf(s, "wo", 3, No.caseSensitive)); // 6
Examples:import std.typecons : No; string s = "Hello World"; writeln(indexOf(s, "Wo")); // 6 writeln(indexOf(s, "Zo")); // -1 writeln(indexOf(s, "wO", No.caseSensitive)); // 6
- pure @safe ptrdiff_t
lastIndexOf(Char)(const(Char)[]s, in dcharc, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char);
pure @safe ptrdiff_tlastIndexOf(Char)(const(Char)[]s, in dcharc, in size_tstartIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char); - Parameters:
const(Char)[] s検索する文字列 dchar c検索する文字 size_t startIdx検索を開始する s のインデックス CaseSensitive csYes.caseSensitive またはNo.caseSensitive Returns:の最後に出現したcである。s.もしcが見つからない場合は が見つからない場合は、-1 が返される。そのstartIdxスライスsを返す。 s[0 .. startIdx] のスライスは次のようになる。startIdxは のコードユニットインデックスを表す。s.Throws:で終わる配列が、井戸を表していない場合startIdxで終わる配列が で終わるシーケンスが正しく形成されたコードポイントを表さない場合 std.utf.UTFExceptionがスローされる。csは、比較が大文字小文字を区別するかどうかを示す。Examples:import std.typecons : No; string s = "Hello World"; writeln(lastIndexOf(s, 'l')); // 9 writeln(lastIndexOf(s, 'Z')); // -1 writeln(lastIndexOf(s, 'L', No.caseSensitive)); // 9
Examples:import std.typecons : No; string s = "Hello World"; writeln(lastIndexOf(s, 'l', 4)); // 3 writeln(lastIndexOf(s, 'Z', 1337)); // -1 writeln(lastIndexOf(s, 'L', 7, No.caseSensitive)); // 3
- pure @safe ptrdiff_t
lastIndexOf(Char1, Char2)(const(Char1)[]s, const(Char2)[]sub, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char1 && isSomeChar!Char2);
pure @safe ptrdiff_tlastIndexOf(Char1, Char2)(const(Char1)[]s, const(Char2)[]sub, in size_tstartIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char1 && isSomeChar!Char2); - Parameters:
const(Char1)[] s検索する文字列 const(Char2)[] sub検索する部分文字列 size_t startIdx検索を開始する s のインデックス CaseSensitive csYes.caseSensitive またはNo.caseSensitive Returns:の最後に現れるsubである。s.もしsubが見つからない場合は が見つからない場合は、-1 が返される。そのstartIdxスライスsは、次のようにs[0 .. startIdx] 。startIdxは のコードユニットインデックスを表す。s.Throws:で終わる配列が、井戸を表していない場合startIdxで終わる配列が で終わるシーケンスが正しく形成されたコードポイントを表さない場合 std.utf.UTFExceptionがスローされる。csは、比較が大文字小文字を区別するかどうかを示す。Examples:import std.typecons : No; string s = "Hello World"; writeln(lastIndexOf(s, "ll")); // 2 writeln(lastIndexOf(s, "Zo")); // -1 writeln(lastIndexOf(s, "lL", No.caseSensitive)); // 2
Examples:import std.typecons : No; string s = "Hello World"; writeln(lastIndexOf(s, "ll", 4)); // 2 writeln(lastIndexOf(s, "Zo", 128)); // -1 writeln(lastIndexOf(s, "lL", 3, No.caseSensitive)); // -1
- pure @safe ptrdiff_t
indexOfAny(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2);
pure @safe ptrdiff_tindexOfAny(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in size_tstartIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2); - needles 。
haystack.の要素が見つからない場合はneedlesの要素が見つからない場合 の要素が見つからない場合は、-1 が返される。の要素が見つからない場合はstartIdxスライスhaystackを返す。 haystack[startIdx .. $] 次のようにスライスする。startIdxは のコードユニットインデックスを表す。haystack.で終わるシーケンスがstartIdxで終わるシーケンスがうまく形成されたコードポイントを表さない場合は std.utf.UTFException がスローされる。Parameters:const(Char)[] haystack針を探す文字列。 const(Char2)[] needles干し草の山から探す文字列。 size_t startIdx干し草の山はこのようにスライスするhaystack[startIdx .. $] 。もし startIdxが干し草の山の長さ以上であれば 関数は-1 を返す。 CaseSensitive cs大文字と小文字を区別するかどうかを示す。 Examples:import std.conv : to; ptrdiff_t i = "helloWorld".indexOfAny("Wr"); writeln(i); // 5 i = "öällo world".indexOfAny("lo "); writeln(i); // 4
Examples:import std.conv : to; ptrdiff_t i = "helloWorld".indexOfAny("Wr", 4); writeln(i); // 5 i = "Foo öällo world".indexOfAny("lh", 3); writeln(i); // 8
- pure @safe ptrdiff_t
lastIndexOfAny(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2);
pure @safe ptrdiff_tlastIndexOfAny(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in size_tstopIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2); - needles 、最後に出現した要素のインデックスを返す。
haystack.の要素が見つからない場合はneedlesの要素が見つからない場合 の要素が見つからない場合は、-1 が返される。の要素が見つからない場合はstopIdxスライスhaystackを返す。 s[0 .. stopIdx] 次のようにスライスする。stopIdxはコードユニットを表す のインデックスを表す。haystack.もしstartIdx で終わるシーケンスが で終わるシーケンスがうまく形成されたコードポイントを表さない場合は std.utf.UTFExceptionが投げられるかもしれない。 がスローされる。Parameters:const(Char)[] haystack針小棒大に探す文字列。 const(Char2)[] needles干し草の山から探す文字列。 size_t stopIdx干し草の山をこのようにスライスするhaystack[0 .. stopIdx].もし stopIdxが干し草の山の長さ以上であれば 関数は-1 を返す。 CaseSensitive cs比較が大文字小文字を区別するかどうかを示す。 Examples:ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo"); writeln(i); // 8 i = "Foo öäöllo world".lastIndexOfAny("öF"); writeln(i); // 8
Examples:import std.conv : to; ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo", 4); writeln(i); // 3 i = "Foo öäöllo world".lastIndexOfAny("öF", 3); writeln(i); // 0
- pure @safe ptrdiff_t
indexOfNeither(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2);
pure @safe ptrdiff_tindexOfNeither(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in size_tstartIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2); - 要素以外の文字が最初に出現するインデックスを返す。 でない
needlesのhaystack.のすべての要素がhaystackのすべての要素が の要素が返される。needles-1 が返される。Parameters:const(Char)[] haystack針小棒大に探す文字列。 const(Char2)[] needles干し草の山から探す文字列。 size_t startIdx干し草の山をこのようにスライスするhaystack[startIdx .. $].もし startIdxが干し草の山の長さ以上であれば 関数は-1 を返す。 CaseSensitive cs大文字と小文字を区別するかどうかを示す。 Examples:writeln(indexOfNeither("abba", "a", 2)); // 2 writeln(indexOfNeither("def", "de", 1)); // 2 writeln(indexOfNeither("dfefffg", "dfe", 4)); // 6
Examples:writeln(indexOfNeither("def", "a")); // 0 writeln(indexOfNeither("def", "de")); // 2 writeln(indexOfNeither("dfefffg", "dfe")); // 6
- pure @safe ptrdiff_t
lastIndexOfNeither(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2);
pure @safe ptrdiff_tlastIndexOfNeither(Char, Char2)(const(Char)[]haystack, const(Char2)[]needles, in size_tstopIdx, in CaseSensitivecs= Yes.caseSensitive)
if (isSomeChar!Char && isSomeChar!Char2); - の要素でない文字が最初に現れる最後のインデックスを返す。 の要素でない文字の
needlesに含まれるhaystack.のすべての要素がhaystackの要素がすべてneedles-1 が返される。Parameters:const(Char)[] haystack針小棒大に探す文字列。 const(Char2)[] needles干し草の山から探す文字列。 size_t stopIdx干し草の山をこのようにスライスするhaystack[0 .. stopIdx] もし stopIdxが干し草の山の長さ以上であれば 関数は-1 を返す。 CaseSensitive cs比較が大文字小文字を区別するかどうかを示す。 Examples:writeln(lastIndexOfNeither("abba", "a")); // 2 writeln(lastIndexOfNeither("def", "f")); // 1
Examples:writeln(lastIndexOfNeither("def", "rsa", 3)); // -1 writeln(lastIndexOfNeither("abba", "a", 2)); // 1
- pure nothrow @nogc @safe auto
representation(Char)(Char[]s)
if (isSomeChar!Char); - 文字列の表現を返す。 を持つ文字列の表現を返す。ただし、文字型はubyte 、 ushort またはuint に置き換わる。Parameters:
Char[] s文字列の表現を返す文字列。 Returns:渡された文字列の表現。Examples:string s = "hello"; static assert(is(typeof(representation(s)) == immutable(ubyte)[])); assert(representation(s) is cast(immutable(ubyte)[]) s); writeln(representation(s)); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
- pure @trusted S
capitalize(S)(Sinput)
if (isSomeString!S); - s の最初の文字を大文字にし、s の残りの文字を小文字に変換する。 を小文字に変換する。Parameters:
S input大文字にする文字列。 Returns:大文字にする文字列。See Also:std.uni.asCapitalizedメモリを割り当てないレイジー・レンジ・バージョンの場合Examples:writeln(capitalize("hello")); // "Hello" writeln(capitalize("World")); // "World"
- alias
KeepTerminator= std.typecons.Flag!"keepTerminator".Flag;
pure @safe C[][]splitLines(C)(C[]s, KeepTerminatorkeepTerm= No.keepTerminator)
if (isSomeChar!C); - 分割する
sを使用してユニコード標準に従って行の配列に分割する。 '\r' '\n' ,"\r\n" 、 std.uni.lineSep, std.uni.paraSepU+0085 (NEL),'\v' および'\f' を区切り文字とする。もしkeepTermがKeepTerminator.yesに設定されている場合は に設定されている場合、区切り文字が返される文字列に含まれる。無効なUTFに対してはスローしない。 をそのまま出力に渡すだけである。 メモリを確保する。 lineSplitterメモリを確保する。 を使う。 Unicode 7.0に従う。Parameters:C[] schars 、wchars 、dchars の文字列、または任意のカスタム型。 string 型にキャストする。 KeepTerminatorkeepTerm区切り文字が結果に含まれるかどうか。 Returns:のスライスである行である。sExamples:string s = "Hello\nmy\rname\nis"; writeln(splitLines(s)); // ["Hello", "my", "name", "is"]
- auto
lineSplitter(KeepTerminator keepTerm = No.keepTerminator, Range)(Ranger)
if (hasSlicing!Range && hasLength!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range);
autolineSplitter(KeepTerminator keepTerm = No.keepTerminator, C)(C[]r)
if (isSomeChar!C); - 文字の配列またはスライス可能な範囲を行の範囲に分割する を使う。 '\
r''\n','\v','\f' 、 "\r\n", std.uni.lineSep, std.uni.paraSepおよび'\u0085' (NEL) を区切り文字とする。keepTerm がYes.keepTerminator に設定されている場合、区切り文字は返されるスライスに含まれる。 に設定されている場合、デリミタは返されるスライスに含まれる。無効なUTFに対してはスローしない。 を出力に渡すだけである。 Unicode 7.0に従う。 メモリを割り当てない。Parameters:Range rchars 、wchars 、dchars の配列、またはスライス可能な範囲。 keepTerm 区切り文字が結果に含まれるかどうか Returns:入力範囲のスライス範囲rExamples:import std.array : array; string s = "Hello\nmy\rname\nis"; /* lineSplitterが作成した遅延範囲をsplitLinesが作成したstring[] と同等にするために'array'を呼び出していることに注目してほしい。 */ writeln(lineSplitter(s).array); // splitLines(s)
Examples:auto s = "\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\nsunday\nmon\u2030day\n"; auto lines = s.lineSplitter(); static immutable witness = ["", "peter", "", "paul", "jerry", "ice", "cream", "", "sunday", "mon\u2030day"]; uint i; foreach (line; lines) { writeln(line); // witness[i++] } writeln(i); // witness.length
- auto
stripLeft(Range)(Rangeinput)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && !isInfinite!Range && !isConvertibleToString!Range);
autostripLeft(Range, Char)(Rangeinput, const(Char)[]chars)
if ((isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char); - で定義される)先頭の空白を除去する。 std.uni.isWhiteまたは 第2引数で指定する。Parameters:
Range input文字列または前方範囲 文字列 const(Char)[] chars取り除かれる文字列 Returns:input先頭の空白または文字を取り除く を除去する。事後条件
inputと戻り値 は同じ末尾を共有する ( std.array.sameTail).See Also:レンジの一般的なストリッピング: std.algorithm.mutation.stripLeftExamples:import std.uni : lineSep, paraSep; assert(stripLeft(" hello world ") == "hello world "); assert(stripLeft("\n\t\v\rhello world\n\t\v\r") == "hello world\n\t\v\r"); assert(stripLeft(" \u2028hello world") == "hello world"); assert(stripLeft("hello world") == "hello world"); assert(stripLeft([lineSep] ~ "hello world" ~ lineSep) == "hello world" ~ [lineSep]); assert(stripLeft([paraSep] ~ "hello world" ~ paraSep) == "hello world" ~ [paraSep]); import std.array : array; import std.utf : byChar; assert(stripLeft(" hello world "w.byChar).array == "hello world "); assert(stripLeft(" \u2022hello world ".byChar).array == "\u2022hello world ");
Examples:assert(stripLeft(" hello world ", " ") == "hello world "); assert(stripLeft("xxxxxhello world ", "x") == "hello world "); assert(stripLeft("xxxyy hello world ", "xy ") == "hello world ");
Examples:import std.array : array; import std.utf : byChar, byWchar, byDchar; assert(stripLeft(" xxxyy hello world "w.byChar, "xy ").array == "hello world "); assert(stripLeft("\u2028\u2020hello world\u2028"w.byWchar, "\u2028").array == "\u2020hello world\u2028"); assert(stripLeft("\U00010001hello world"w.byWchar, " ").array == "\U00010001hello world"w); assert(stripLeft("\U00010001 xyhello world"d.byDchar, "\U00010001 xy").array == "hello world"d); writeln(stripLeft("\u2020hello"w, "\u2020"w)); // "hello"w writeln(stripLeft("\U00010001hello"d, "\U00010001"d)); // "hello"d writeln(stripLeft(" hello ", "")); // " hello "
- auto
stripRight(Range)(Rangestr)
if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range));
autostripRight(Range, Char)(Rangestr, const(Char)[]chars)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char); - で定義されている) 末尾の空白を除去する。 std.uni.isWhiteまたは 第2引数で指定されたParameters:
Range str文字列またはランダムアクセス可能な文字の範囲 const(Char)[] chars取り除かれる文字列 Returns:スライスstr末尾の空白または文字を除去する。 のスライスである。See Also:レンジの一般的なストリッピング: std.algorithm.mutation.stripRightExamples:import std.uni : lineSep, paraSep; assert(stripRight(" hello world ") == " hello world"); assert(stripRight("\n\t\v\rhello world\n\t\v\r") == "\n\t\v\rhello world"); assert(stripRight("hello world") == "hello world"); assert(stripRight([lineSep] ~ "hello world" ~ lineSep) == [lineSep] ~ "hello world"); assert(stripRight([paraSep] ~ "hello world" ~ paraSep) == [paraSep] ~ "hello world");
Examples:assert(stripRight(" hello world ", "x") == " hello world "); assert(stripRight(" hello world ", " ") == " hello world"); assert(stripRight(" hello worldxy ", "xy ") == " hello world");
- auto
strip(Range)(Rangestr)
if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range));
autostrip(Range, Char)(Rangestr, const(Char)[]chars)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char);
autostrip(Range, Char)(Rangestr, const(Char)[]leftChars, const(Char)[]rightChars)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char); - で定義されている)先頭と末尾の空白を除去する。 std.uni.isWhiteで定義されている)、または第2引数で指定されたParameters:
Range str文字列またはランダムアクセス可能な文字の範囲 const(Char)[] chars取り除かれる文字列 const(Char)[] leftChars取り除かれる先頭文字の文字列 const(Char)[] rightChars取り除かれる末尾の文字列 Returns:スライスstr先頭と末尾の空白を取り除く または第2引数で指定された文字を取り除く。See Also:レンジの一般的なストリッピング: std.algorithm.mutation.stripExamples:import std.uni : lineSep, paraSep; assert(strip(" hello world ") == "hello world"); assert(strip("\n\t\v\rhello world\n\t\v\r") == "hello world"); assert(strip("hello world") == "hello world"); assert(strip([lineSep] ~ "hello world" ~ [lineSep]) == "hello world"); assert(strip([paraSep] ~ "hello world" ~ [paraSep]) == "hello world");
Examples:assert(strip(" hello world ", "x") == " hello world "); assert(strip(" hello world ", " ") == "hello world"); assert(strip(" xyxyhello worldxyxy ", "xy ") == "hello world"); writeln(strip("\u2020hello\u2020"w, "\u2020"w)); // "hello"w writeln(strip("\U00010001hello\U00010001"d, "\U00010001"d)); // "hello"d writeln(strip(" hello ", "")); // " hello "
Examples:writeln(strip("xxhelloyy", "x", "y")); // "hello" assert(strip(" xyxyhello worldxyxyzz ", "xy ", "xyz ") == "hello world"); writeln(strip("\u2020hello\u2028"w, "\u2020"w, "\u2028"w)); // "hello"w assert(strip("\U00010001hello\U00010002"d, "\U00010001"d, "\U00010002"d) == "hello"d); writeln(strip(" hello ", "", "")); // " hello "
- Range
chomp(Range)(Rangestr)
if ((isRandomAccessRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range);
Rangechomp(Range, C2)(Rangestr, const(C2)[]delimiter)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range && isSomeChar!C2); - もし
strで終わる。delimiterで終わる場合はstrを付けずに返される。delimiterを付けずに返される。もしstrで終わらない場合はdelimiterで終わっていなければ、変更されずに返される。もしdelimiterがない場合、末尾に'\r','\n' 、 "\r\n" '\f' ,'\v' 、 std.uni.lineSep, std.uni.paraSepまたは std.uni.nelSep の末尾が削除される。str.もしstrの末尾がこれらの文字のいずれでもない場合 で終わっていなければ、そのまま返される。Parameters:Range str文字列またはインデックス可能な文字の範囲 const(C2)[] delimiterstr[]の末尾からスライスされる文字列 Returns:strのスライスExamples:import std.uni : lineSep, paraSep, nelSep; import std.utf : decode; writeln(chomp(" hello world \n\r")); // " hello world \n" writeln(chomp(" hello world \r\n")); // " hello world " writeln(chomp(" hello world \f")); // " hello world " writeln(chomp(" hello world \v")); // " hello world " writeln(chomp(" hello world \n\n")); // " hello world \n" writeln(chomp(" hello world \n\n ")); // " hello world \n\n " writeln(chomp(" hello world \n\n" ~ [lineSep])); // " hello world \n\n" writeln(chomp(" hello world \n\n" ~ [paraSep])); // " hello world \n\n" writeln(chomp(" hello world \n\n" ~ [nelSep])); // " hello world \n\n" writeln(chomp(" hello world ")); // " hello world " writeln(chomp(" hello world")); // " hello world" writeln(chomp("")); // "" writeln(chomp(" hello world", "orld")); // " hello w" writeln(chomp(" hello world", " he")); // " hello world" writeln(chomp("", "hello")); // "" // 無意味なデコードをしない writeln(chomp("hello\xFE", "\r")); // "hello\xFE"
- Range
chompPrefix(Range, C2)(Rangestr, const(C2)[]delimiter)
if ((isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range && isSomeChar!C2); - もし
strで始まる場合delimiterで始まる場合はstr以下のようになる。delimiterの部分が返される。もしstrで始まらない場合はdelimiterで始まらない場合は、変更されずに返される。Parameters:Range str文字列または前方範囲 文字列 const(C2)[] delimiterstr[]の前を切り取る文字列 Returns:strのスライスExamples:writeln(chompPrefix("hello world", "he")); // "llo world" writeln(chompPrefix("hello world", "hello w")); // "orld" writeln(chompPrefix("hello world", " world")); // "hello world" writeln(chompPrefix("", "hello")); // ""
- Range
chop(Range)(Rangestr)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range); - を返す。
str最後の文字があれば、その文字を除いたものを返す。もしstrの末尾が"\r\n" である場合は、両方が削除される。もしstrが空なら は変更されずに返される。Parameters:Range str文字列(有効なUTFでなければならない) Returns:strのスライスExamples:writeln(chop("hello world")); // "hello worl" writeln(chop("hello world\n")); // "hello world" writeln(chop("hello world\r")); // "hello world" writeln(chop("hello world\n\r")); // "hello world\n" writeln(chop("hello world\r\n")); // "hello world" writeln(chop("Walter Bright")); // "Walter Brigh" writeln(chop("")); // ""
- S
leftJustify(S)(Ss, size_twidth, dcharfillChar= ' ')
if (isSomeString!S); - 左寄せにする
sフィールドのwidth文字幅で左寄せにする。fillCharは、フィールド内のスペースを埋めるために使われる文字である。sを埋めるために使われる文字である。Parameters:S s文字列 size_t width最小フィールド幅 dchar fillChar末尾を width文字Returns:GCに割り当てられた文字列See Also:leftJustifierを割り当てない。Examples:writeln(leftJustify("hello", 7, 'X')); // "helloXX" writeln(leftJustify("hello", 2, 'X')); // "hello" writeln(leftJustify("hello", 9, 'X')); // "helloXXXX"
- auto
leftJustifier(Range)(Ranger, size_twidth, dcharfillChar= ' ')
if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range); - s 。
width文字幅で表示する。fillCharは、フィールドに入りきらないスペースを埋めるために使われる文字である。 s を埋めるために使われる文字である。Parameters:Range r文字列または文字の範囲 size_t width最小フィールド幅 dchar fillChar末尾を width文字Returns:左詰めの結果の遅延範囲See Also:Examples:import std.algorithm.comparison : equal; import std.utf : byChar; assert(leftJustifier("hello", 2).equal("hello".byChar)); assert(leftJustifier("hello", 7).equal("hello ".byChar)); assert(leftJustifier("hello", 7, 'x').equal("helloxx".byChar));
- S
rightJustify(S)(Ss, size_twidth, dcharfillChar= ' ')
if (isSomeString!S); - 右揃え
sフィールドでwidth文字幅で右寄せにする。fillCharがフィールドのスペースを埋めるために使われる文字である。sを埋めるために使われる文字である。Parameters:S s文字列 size_t width最小フィールド幅 dchar fillChar末尾を width文字Returns:GCに割り当てられた文字列See Also:rightJustifierを割り当てない。Examples:writeln(rightJustify("hello", 7, 'X')); // "XXhello" writeln(rightJustify("hello", 2, 'X')); // "hello" writeln(rightJustify("hello", 9, 'X')); // "XXXXhello"
- auto
rightJustifier(Range)(Ranger, size_twidth, dcharfillChar= ' ')
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range); - s 。
width文字幅で表示する。fillCharは、フィールドに入りきらないスペースを埋めるために使われる文字である。 s を埋めるために使われる文字である。Parameters:Range r文字列または前方範囲 文字の size_t width最小フィールド幅 dchar fillChar末尾を width文字Returns:右寄せ結果の遅延範囲See Also:Examples:import std.algorithm.comparison : equal; import std.utf : byChar; assert(rightJustifier("hello", 2).equal("hello".byChar)); assert(rightJustifier("hello", 7).equal(" hello".byChar)); assert(rightJustifier("hello", 7, 'x').equal("xxhello".byChar));
- S
center(S)(Ss, size_twidth, dcharfillChar= ' ')
if (isSomeString!S); - センター
sフィールドwidth文字の幅がある。fillCharは、フィールドのスペースを埋めるために使用される文字である。sを埋めるために使われる文字である。Parameters:S s中央に配置する文字列 size_t widthセンタリングするフィールドの幅 sindchar fillCharフィールド内の余分なスペースを埋めるために使用する文字 Returns:結果として得られる中央揃え文字列。返された文字列は GCに割り当てられる。GC割り当てを避けるには centerJustifier を使う。Examples:writeln(center("hello", 7, 'X')); // "XhelloX" writeln(center("hello", 2, 'X')); // "hello" writeln(center("hello", 9, 'X')); // "XXhelloXX"
- auto
centerJustifier(Range)(Ranger, size_twidth, dcharfillChar= ' ')
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range); - 中央揃え
rフィールドwidth文字幅で中央揃えする。fillCharがフィールドのスペースを埋めるために使われる文字である。rを埋めるために使われる文字である。Parameters:Range r文字列または前方範囲 文字数 size_t width最小フィールド幅 dchar fillChar末尾を width文字Returns:中央揃え結果の遅延範囲See Also:Examples:import std.algorithm.comparison : equal; import std.utf : byChar; assert(centerJustifier("hello", 2).equal("hello".byChar)); assert(centerJustifier("hello", 8).equal(" hello ".byChar)); assert(centerJustifier("hello", 7, 'x').equal("xhellox".byChar));
- pure auto
detab(Range)(auto ref Ranges, size_ttabSize= 8)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) || __traits(compiles, StringTypeOf!Range)); - の各タブ文字を
sの各タブ文字を 次の文字を次のタブストップに揃えるのに必要なスペース数に置き換える。Parameters:Range s文字列 size_t tabSizeタブストップ間の距離 Returns:タブをスペースに置き換えたGC割当文字列Examples:writeln(detab(" \n\tx", 9)); // " \n x"
- auto
detabber(Range)(Ranger, size_ttabSize= 8)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range);
autodetabber(Range)(auto ref Ranger, size_ttabSize= 8)
if (isConvertibleToString!Range); - の各タブ文字を
rの各タブ文字を、次の文字を次のタブストップに揃えるのに必要な 次の文字を次のタブストップに揃えるのに必要なスペース数に置き換える。Parameters:Range r文字列または前方範囲 size_t tabSizeタブストップ間の距離 Returns:タブをスペースに置き換えた遅延前方範囲Examples:import std.array : array; writeln(detabber(" \n\tx", 9).array); // " \n x"
Examples:import std.array : array; import std.utf : byChar, byWchar; writeln(detabber(" \u2029\t".byChar, 9).array); // " \u2029 " auto r = "hel\tx".byWchar.detabber(); writeln(r.front); // 'h' auto s = r.save; r.popFront(); r.popFront(); writeln(r.front); // 'l' writeln(s.front); // 'h'
- auto
entab(Range)(Ranges, size_ttabSize= 8)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range)); - のスペースを
sを最適な数のタブに置き換える。 行末のスペースとタブはすべて削除される。Parameters:Range s変換する文字列。 size_t tabSizeタブの列は tabSizeスペースで区切られる。Returns:GCで割り当てられた文字列は、スペースがタブに置き換えられている; を使う。 entabberを使う。See Also:Examples:writeln(entab(" x \n")); // "\tx\n"
- auto
entabber(Range)(Ranger, size_ttabSize= 8)
if (isForwardRange!Range && !isConvertibleToString!Range); - 範囲内のスペースを最適なタブ数に置き換える。
rを最適な数のタブで置き換える。 行末のスペースとタブはすべて削除される。Parameters:Range r文字列または前方範囲 size_t tabSizeタブストップ間の距離 Returns:空白をタブに置き換えた怠惰な前方範囲See Also:Examples:import std.array : array; writeln(entabber(" x \n").array); // "\tx\n"
- pure @safe C1[]
translate(C1, C2 = immutable(char))(C1[]str, in dchar[dchar]transTable, const(C2)[]toRemove= null)
if (isSomeChar!C1 && isSomeChar!C2);
pure @safe C1[]translate(C1, S, C2 = immutable(char))(C1[]str, in S[dchar]transTable, const(C2)[]toRemove= null)
if (isSomeChar!C1 && isSomeString!S && isSomeChar!C2); - の文字を置き換える。
strのキーであるtransTableのキーである の対応する値に置き換える。transTable.transTableはAAである。 で、キーはdchar 、値はdchar または何らかの文字列である。 の文字列である。またtoRemoveが与えられた場合、その中の文字は から削除される。strから削除される。str自体は変更されない。 変更されたコピーが返される。Parameters:C1[] str元の文字列。 dchar[dchar] transTableどの文字を何に置き換えるかを示すAA。 で置き換える。 const(C2)[] toRemove文字列から削除する文字。 Examples:dchar[dchar] transTable1 = ['e' : '5', 'o' : '7', '5': 'q']; writeln(translate("hello world", transTable1)); // "h5ll7 w7rld" writeln(translate("hello world", transTable1, "low")); // "h5 rd" string[dchar] transTable2 = ['e' : "5", 'o' : "orange"]; writeln(translate("hello world", transTable2)); // "h5llorange worangerld"
- void
translate(C1, C2 = immutable(char), Buffer)(const(C1)[]str, in dchar[dchar]transTable, const(C2)[]toRemove, Bufferbuffer)
if (isSomeChar!C1 && isSomeChar!C2 && isOutputRange!(Buffer, C1));
voidtranslate(C1, S, C2 = immutable(char), Buffer)(C1[]str, in S[dchar]transTable, const(C2)[]toRemove, Bufferbuffer)
if (isSomeChar!C1 && isSomeString!S && isSomeChar!C2 && isOutputRange!(Buffer, S)); - これは
translateのオーバーロードであり、内容を書き込むために既存のバッファを受け取る。Parameters:const(C1)[] str元の文字列。 dchar[dchar] transTableどの文字を何に置き換えるかを示すAA で置き換える。 const(C2)[] toRemove文字列から削除する文字。 Buffer buffer内容を書き込む出力範囲。 Examples:import std.array : appender; dchar[dchar] transTable1 = ['e' : '5', 'o' : '7', '5': 'q']; auto buffer = appender!(dchar[])(); translate("hello world", transTable1, null, buffer); writeln(buffer.data); // "h5ll7 w7rld" buffer.clear(); translate("hello world", transTable1, "low", buffer); writeln(buffer.data); // "h5 rd" buffer.clear(); string[dchar] transTable2 = ['e' : "5", 'o' : "orange"]; translate("hello world", transTable2, null, buffer); writeln(buffer.data); // "h5llorange worangerld"
- pure nothrow @trusted C[]
translate(C = immutable(char))(scope const(char)[]str, scope const(char)[]transTable, scope const(char)[]toRemove= null)
if (is(immutable(C) == immutable(char))); - のASCIIのみのオーバーロードである。 translate.のオーバーロードである。 のオーバーロードであり、Unicodeでは動作しない。これは の最適化として存在する。の他のオーバーロードとは異なり translateの他のオーバーロードとは異なり、これは AAを取らない。string むしろ makeTransTable. makeTransTable によって生成される配列は、256 要素長である。 インデックスは置換されるASCII文字に等しく、値は置換される文字に等しい。 は置換される文字に等しい。translate:」はどの文字もデコードしないことに注意されたい。 は文字をデコードしないので、実際には拡張された ASCII文字(ASCIIは実際には128 文字しか使用しない)。ただし、拡張ASCII文字は有効な 拡張ASCII文字は有効なUnicodeではないため、他のほとんどのPhobos関数からUTFException 。 がスローされることになるので注意すること。 また、デコードが行われないので、このオーバーロードを使用して 文字列内の ASCII 文字を変換することができる。 他の非ASCII文字を変更することなく、適切なUTF-8文字列内のASCII文字を変換することができる。を超えるコード・ユニットを別のコード・ユニットに置き換えたり、あるいは 127 より大きいコード・ユニットを別のコード・ユニットに置き換えるか、あるいは、 より大きいコード・ユニットを別のコード・ユニットに置き換えることである。 より大きいコード・ユニットを別のコード・ユニットに置き換えたり、127 より大きいコード・ユニットを別のコード・ユニットに置き換えたりすることである。Parameters:
const(char)[] str元の文字列。 const(char)[] transTableどの文字を何に置き換えるかを示す で置き換えるかを示す文字列である。これは makeTransTable. const(char)[] toRemove文字列から削除する文字。 Examples:auto transTable1 = makeTrans("eo5", "57q"); writeln(translate("hello world", transTable1)); // "h5ll7 w7rld" writeln(translate("hello world", transTable1, "low")); // "h5 rd"
- pure nothrow @trusted string
makeTrans(scope const(char)[]from, scope const(char)[]to); - と同じことを行う。 makeTransTableと同じことをするが、変換テーブル をGCヒープに割り当てる。代わりに makeTransTableを使う。Examples:
auto transTable1 = makeTrans("eo5", "57q"); writeln(translate("hello world", transTable1)); // "h5ll7 w7rld" writeln(translate("hello world", transTable1, "low")); // "h5 rd"
- pure nothrow @nogc @safe char[256]
makeTransTable(scope const(char)[]from, scope const(char)[]to); - 256文字の変換テーブルを作成する。 の文字をto[]の対応する文字に置き換える。Parameters:
const(char)[] from長さが256以下の文字の配列 const(char)[] to変換先の文字に対応する配列 Returns:翻訳配列Examples:writeln(translate("hello world", makeTransTable("hl", "q5"))); // "qe55o wor5d" writeln(translate("hello world", makeTransTable("12345", "67890"))); // "hello world"
- pure @trusted void
translate(C = immutable(char), Buffer)(scope const(char)[]str, scope const(char)[]transTable, scope const(char)[]toRemove, Bufferbuffer)
if (is(immutable(C) == immutable(char)) && isOutputRange!(Buffer, char)); - のASCIIのみのオーバーロードである。
translateのオーバーロードであり、内容を書き込むために既存のバッファを取る。Parameters:const(char)[] str元の文字列。 const(char)[] transTableどの文字を何に置き換えるかを示す で置き換えるかを示す文字列。これは makeTransTable. const(char)[] toRemove文字列から削除する文字。 Buffer buffer内容を書き込む出力範囲。 Examples:import std.array : appender; auto buffer = appender!(char[])(); auto transTable1 = makeTransTable("eo5", "57q"); translate("hello world", transTable1, null, buffer); writeln(buffer.data); // "h5ll7 w7rld" buffer.clear(); translate("hello world", transTable1, "low", buffer); writeln(buffer.data); // "h5 rd"
- pure @safe S
succ(S)(Ss)
if (isSomeString!S); - s[]の「後継」となる文字列を返す。 右端の文字がa-zA-Z0-9の場合、大文字と小文字の区別がない。 大文字と小文字の区別なくインクリメントされる。キャリーが発生した場合は、そのすぐ左の文字でこの処理が繰り返される。 を繰り返す。Examples:
writeln(succ("1")); // "2" writeln(succ("9")); // "10" writeln(succ("999")); // "1000" writeln(succ("zz99")); // "aaa00"
- C1[]
tr(C1, C2, C3, C4 = immutable(char))(C1[]str, const(C2)[]from, const(C3)[]to, const(C4)[]modifiers= null); - の文字を置き換える。
strであるfromにある文字を の対応する文字をtoに置き換え、結果の文字列を返す。trは をベースにしている、 をベースにしているが、Posixユーティリティが行うことをすべて行うわけではない。Parameters:C1[] str元の文字列。 const(C2)[] from置換する文字。 const(C3)[] to置換する文字。 const(C4)[] modifiers修飾子を含む文字列。 修飾子
修飾子'd' が指定されている場合、置換後の文字数は修飾子 説明 'c' の文字のリストを補完する。 from'd' 一致する文字を削除する。 で置換する。 to's' 置換された 文字 toの文字数は0 または1 だけである。 修飾子'd' が存在せず、かつtoが空ならtoと同じとみなされる。from. 修飾子'd' が存在せず、かつtoよりも短い場合はfromより短い場合はtoの最後の文字を複製することで拡張される。to. とfromとtoは、'-' 文字を使った範囲を含むことができる。 (例えば、"a-d" は"abcd" と同義である。 '^' を文字列の補数を意味するものとして受け付けない(その場合は'c' 修飾子 を使う)。Examples:writeln(tr("abcdef", "cd", "CD")); // "abCDef" writeln(tr("1st March, 2018", "March", "MAR", "s")); // "1st MAR, 2018" writeln(tr("abcdef", "ef", "", "d")); // "abcd" writeln(tr("14-Jul-87", "a-zA-Z", " ", "cs")); // " Jul "
- bool
isNumeric(S)(Ss, boolbAllowSep= false)
if (isSomeString!S || isRandomAccessRange!S && hasSlicing!S && isSomeChar!(ElementType!S) && !isInfinite!S); - 文字列
sを受け取り、それが数値を表すかどうかを判定する。この"関数"はオプションのパラメータも取る。 はオプションのパラメータbAllowSepを受け付ける。 ',' '__' を受け付ける。しかし、これらの のような変換関数を使う前に、文字列からこれらの文字を取り除かなければならない。 to!int() ,to!float(), などの変換関数を使う前に、文字列からこれらの文字を取り除かなければならない。 のような変換関数を使う前に、文字列からこれらの文字を取り除かなければならない。また、文字列の中にスペースを入れることは許されない。 文字列内では、先頭、末尾、埋め込みスペースにかかわらず、スペースは使用できない、 したがって、この関数や変換関数を使用する前に、文字列からスペースを取り除かなければならない。 関数や変換関数を使う前に、文字列から空白を取り除かなければならない。Parameters:S sチェックする文字列またはランダムアクセス範囲 bool bAllowSep区切り文字を受け入れるかどうか Returns:boolExamples:整数の整数:(byte、ubyte、short、ushort、int、uint、long、ulong) ['+'|'-']桁数[U|L|UL].assert(isNumeric("123")); assert(isNumeric("123UL")); assert(isNumeric("123L")); assert(isNumeric("+123U")); assert(isNumeric("-123L"));
Examples:浮動小数点数:(float、double、real、ifloat、idouble、ireal) ['+'|'-']digit(s)[.][digit(s)][[e-|e+]digit(s)][i|f|L|Li|fi]]. または[nan|nani|inf|-inf]である。assert(isNumeric("+123")); assert(isNumeric("-123.01")); assert(isNumeric("123.3e-10f")); assert(isNumeric("123.3e-10fi")); assert(isNumeric("123.3e-10L")); assert(isNumeric("nan")); assert(isNumeric("nani")); assert(isNumeric("-inf"));
Examples:浮動小数点数: (cfloat, cdouble, creal) ['+'|'-']digit(s)[.][digit(s)][[e-|e+]digit(s)][+] 桁][.][桁][[e-|e+]桁][[i|f|L|Li|fi]]である。 または[nan|nani|nan+nani|inf|-inf]である。assert(isNumeric("-123e-1+456.9e-10Li")); assert(isNumeric("+123e+10+456i")); assert(isNumeric("123+456"));
Examples:isNumericはCTFEで動作するenum a = isNumeric("123.00E-5+1234.45E-12Li"); enum b = isNumeric("12345xxxx890"); static assert( a); static assert(!b);
- char[4]
soundexer(Range)(Rangestr)
if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range) && !isConvertibleToString!Range);
char[4]soundexer(Range)(auto ref Rangestr)
if (isConvertibleToString!Range); - Soundexアルゴリズム。サウンデックス・アルゴリズムは、単語を4文字に変換する。 に変換する。つまり 同じ発音をする2つの綴りは、同じSoundex 値が同じになるということである。 ということである。Parameters:
Range strSoundex表現に変換する文字列またはInputRange。 Returns:Soundex結果を含む4文字の配列。 文字列のSoundex表現がない場合、配列には0が入る。See Also:注釈: 英語名のみ有効である。 英語の名前でのみうまく機能する。
Examples:writeln(soundexer("Gauss")); // "G200" writeln(soundexer("Ghosh")); // "G200" writeln(soundexer("Robert")); // "R163" writeln(soundexer("Rupert")); // "R163" writeln(soundexer("0123^&^^**&^")); // ['\0', '\0', '\0', '\0']
- pure nothrow @safe char[]
soundex(scope const(char)[]str, return scope char[]buffer= null); - のようなものだ。 soundexerと似ているが、パラメータ と戻り値が異なる。Parameters:
const(char)[] strSoundex表現に変換する文字列。 char[] bufferオプションの4文字配列。 の文字を入れる。NULLの場合、戻り値 バッファがヒープ上に確保される。 Returns:Soundex結果を含む4文字の配列。 文字列に対応するSoundex表現がない場合はnullを返す。See Also:Examples:writeln(soundex("Gauss")); // "G200" writeln(soundex("Ghosh")); // "G200" writeln(soundex("Robert")); // "R163" writeln(soundex("Rupert")); // "R163" writeln(soundex("0123^&^^**&^")); // null
- pure @safe string[string]
abbrev(string[]values); - 値の文字列と一意に対応する で構成される連想配列を構築する。これは、ユーザが既知の文字列のうちの1つを "型"で入力するような場合に便利である。 を入力するような場合に便利である。 プログラムが、文字列を一意に識別するのに十分な文字が入力されると、その文字列をオートコンプリートしてくれる。 入力されると、プログラムはその文字列を自動補完する。Examples:
import std.string; static string[] list = [ "food", "foxy" ]; auto abbrevs = abbrev(list); assert(abbrevs == ["fox": "foxy", "food": "food", "foxy": "foxy", "foo": "food"]);
- size_t
column(Range)(Rangestr, in size_ttabsize= 8)
if ((isInputRange!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range); - 表示された文字列の末尾の列番号を計算する、 文字列は左端の列から始まると仮定する。 0から始まる。タブ文字は、列番号がタブサイズの次の倍数になるように十分なスペースに展開される。 をタブサイズの次の倍数にするのに十分なスペースに展開される。 文字列内に複数行がある場合は、最後の行の列番号が返される。 が返される。Parameters:
Range str分析対象の文字列またはInputRange size_t tabsizeタブ文字が表す列数 Returns:列番号Examples:import std.utf : byChar, byWchar, byDchar; writeln(column("1234 ")); // 5 writeln(column("1234 "w)); // 5 writeln(column("1234 "d)); // 5 writeln(column("1234 ".byChar())); // 5 writeln(column("1234 "w.byWchar())); // 5 writeln(column("1234 "d.byDchar())); // 5 // Tab stops are set at 8 spaces by default; タブ文字は、列の位置を // 次の8の倍数にするのに十分なスペースを挿入する。 writeln(column("\t")); // 8 writeln(column("1\t")); // 8 writeln(column("\t1")); // 9 writeln(column("123\t")); // 8 // 明示的に指定すれば、他のタブ幅も可能である: writeln(column("\t", 4)); // 4 writeln(column("1\t", 4)); // 4 writeln(column("\t1", 4)); // 5 writeln(column("123\t", 4)); // 4 // 新しい行は列番号をリセットする。 writeln(column("abc\n")); // 0 writeln(column("abc\n1")); // 1 writeln(column("abcdefg\r1234")); // 4 writeln(column("abc\u20281")); // 1 writeln(column("abc\u20291")); // 1 writeln(column("abc\u00851")); // 1 writeln(column("abc\u00861")); // 5
- S
wrap(S)(Ss, in size_tcolumns= 80, Sfirstindent= null, Sindent= null, in size_ttabsize= 8)
if (isSomeString!S); - テキストを段落にまとめる。入力テキスト文字列sを段落にする。 に分割される。 nで区切られた行のシーケンスに分割することで段落を形成する。 で区切られる。 最後の行の終わりは、"˶" で終わる。Parameters:
S s折り返すテキスト文字列 size_t columns段落の最大列数 S firstindent段落の最初の行のインデントに使う文字列 S indent段落の次の行のインデントに使用する文字列 size_t tabsizefirstindent[]とindent[]のタブの列間隔 Returns:割り当てられた文字列としての結果の段落Examples:writeln(wrap("a short string", 7)); // "a short\nstring\n" // wrapは単語の中では改行されず、次のスペースで改行される writeln(wrap("a short string", 4)); // "a\nshort\nstring\n" writeln(wrap("a short string", 7, "\t")); // "\ta\nshort\nstring\n" writeln(wrap("a short string", 7, "\t", " ")); // "\ta\n short\n string\n"
- pure @safe S
outdent(S)(Sstr)
if (isSomeString!S); - 複数行の文字列から1レベルのインデントを削除する。これにより、テキストは可能な限り一様に字下げされる。 空白のみの行は常に空白行に変換される。 スローしない場合はメモリを確保しない。Parameters:
S str複数行の文字列 Returns:外側の文字列Throws:異なる空白文字のシーケンスでインデントが行われた場合、StringExceptionが発生する。 例外が発生する。Examples:enum pretty = q{ import std.stdio; void main() { writeln("Hello"); } }.outdent(); enum ugly = q{ import std.stdio; void main() { writeln("Hello"); } }; writeln(pretty); // 醜い
- pure @safe S[]
outdent(S)(return scope S[]lines)
if (isSomeString!S); - 単一行文字列の配列から1レベルのインデントを削除する。これにより、テキストは可能な限り一様に字下げされる。 空白のみの行は常に空白行に変換される。Parameters:
S[] lines一行文字列の配列 Returns:lines[]は、改行されていない行で置き換えられる。Throws:異なる空白文字のシーケンスでインデントが行われた場合、StringExceptionが発生する。 例外が発生する。Examples:auto str1 = [ " void main()\n", " {\n", " test();\n", " }\n" ]; auto str1Expected = [ "void main()\n", "{\n", " test();\n", "}\n" ]; writeln(str1.outdent); // str1Expected auto str2 = [ "void main()\n", " {\n", " test();\n", " }\n" ]; writeln(str2.outdent); // str2
- auto
assumeUTF(T)(T[]arr)
if (staticIndexOf!(immutable(T), immutable(ubyte), immutable(ushort), immutable(uint)) != -1); - 与えられた整数の配列
arrの配列が整形されたUTF文字列であると仮定する。 UTF文字列として型付けして返す。ubyte は に、 は に、そして は となる。型修飾子は保持される。 デバッグ・モードでコンパイルされた場合、この関数は戻り値が有効なUnicode文字列であることを確認するための追加チェックを行う。 この関数は、返り値が有効なUnicode文字列であることを確認するための追加チェックを行う。 char ushort wchar uint dcharParameters:T[] arrbyte、ubyte、shorts、ushort、ints、uintsの配列 Returns:arはchars、wchar、dcharの配列として再入力される。Throws:デバッグモードでは、AssertError 、結果が整形式UTF文字列でない場合。See Also:Examples:string a = "Hölo World"; immutable(ubyte)[] b = a.representation; string c = b.assumeUTF; writeln(c); // "Hölo World"
Copyright © 1999-2025 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
サイト全体のドキュメントのdmdのバージョン: 2.109.1
最新のdmdのバージョン: 2.111.0 ダウンロード
翻訳日付:
HTML生成日時:
編集者: dokutoku