Rune 结构

定义

表示 Unicode 标量值([ U+0000..U+D7FF ],含首尾值;或 [ U+E000..U+10FFFF ],含首尾值)。Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive).

public value class Rune : IComparable<System::Text::Rune>, IEquatable<System::Text::Rune>
public struct Rune : IComparable<System.Text.Rune>, IEquatable<System.Text.Rune>
type Rune = struct
Public Structure Rune
Implements IComparable(Of Rune), IEquatable(Of Rune)
继承
实现

注解

Rune 实例表示一个 Unicode 标量值,这意味着任何不包括代理项范围(U + D800)的码位。U + DFFF)。A Rune instance represents a Unicode scalar value, which means any code point excluding the surrogate range (U+D800..U+DFFF). 类型的构造函数和转换运算符验证输入,因此使用者可以调用 Api,假定基础 Rune 实例的格式正确。The type's constructors and conversion operators validate the input, so consumers can call the APIs assuming that the underlying Rune instance is well formed.

如果你不熟悉 Unicode 标量值、代码点、代理项范围和格式正确的术语,请参阅.net 中的字符编码简介If you aren't familiar with the terms Unicode scalar value, code point, surrogate range, and well-formed, see Introduction to character encoding in .NET.

以下各节将对此进行说明:The following sections explain:

何时使用 Rune 类型When to use the Rune type

如果你的代码,请考虑使用 Rune 类型:Consider using the Rune type if your code:

  • 调用需要 Unicode 标量值的 ApiCalls APIs that require Unicode scalar values
  • 显式处理代理项对Explicitly handles surrogate pairs

需要 Unicode 标量值的 ApiAPIs that require Unicode scalar values

如果代码循环访问 stringReadOnlySpan<char>中的 char 实例,则某些 char 方法将无法在代理项范围内的 char 实例上正常工作。If your code iterates through the char instances in a string or a ReadOnlySpan<char>, some of the char methods won't work correctly on char instances that are in the surrogate range. 例如,以下 Api 需要标量值 char 才能正常工作:For example, the following APIs require a scalar value char to work correctly:

下面的示例演示如果有任何 char 实例是代理项码位,则无法正常工作的代码:The following example shows code that won't work correctly if any of the char instances are surrogate code points:

// THE FOLLOWING METHOD SHOWS INCORRECT CODE.
// DO NOT DO THIS IN A PRODUCTION APPLICATION.
int CountLettersBadExample(string s)
{
    int letterCount = 0;

    foreach (char ch in s)
    {
        if (char.IsLetter(ch))
        { letterCount++; }
    }

    return letterCount;
}

下面是适用于 ReadOnlySpan<char>的等效代码:Here's equivalent code that works with a ReadOnlySpan<char>:

// THE FOLLOWING METHOD SHOWS INCORRECT CODE.
// DO NOT DO THIS IN A PRODUCTION APPLICATION.
static int CountLettersBadExample(ReadOnlySpan<char> span)
{
    int letterCount = 0;

    foreach (char ch in span)
    {
        if (char.IsLetter(ch))
        { letterCount++; }
    }

    return letterCount;
}

前面的代码使用某些语言(如英语)正常工作:The preceding code works correctly with some languages such as English:

CountLettersInString("Hello")
// Returns 5

但对于基本多语言平面以外的语言(如 Osage),它将无法正常工作:But it won't work correctly for languages outside the Basic Multilingual Plane, such as Osage:

CountLettersInString("𐓏𐓘𐓻𐓘𐓻𐓟 𐒻𐓟")
// Returns 0

此方法返回不正确的 Osage 文本结果的原因是 Osage 字母的 char 实例是代理项码位。The reason this method returns incorrect results for Osage text is that the char instances for Osage letters are surrogate code points. 没有单个代理项码位具有足够的信息来确定它是否是字母。No single surrogate code point has enough information to determine if it's a letter.

如果将此代码更改为使用 Rune 而不是 char,则方法将与基本多语言平面之外的代码点一起正常工作:If you change this code to use Rune instead of char, the method works correctly with code points outside the Basic Multilingual Plane:

int CountLetters(string s)
{
    int letterCount = 0;

    foreach (Rune rune in s.EnumerateRunes())
    {
        if (Rune.IsLetter(rune))
        { letterCount++; }
    }

    return letterCount;
}

下面是适用于 ReadOnlySpan<char>的等效代码:Here's equivalent code that works with a ReadOnlySpan<char>:

static int CountLetters(ReadOnlySpan<char> span)
{
    int letterCount = 0;

    foreach (Rune rune in span.EnumerateRunes())
    {
        if (Rune.IsLetter(rune))
        { letterCount++; }
    }

    return letterCount;
}

前面的代码会正确统计 Osage 字母:The preceding code counts Osage letters correctly:

CountLettersInString("𐓏𐓘𐓻𐓘𐓻𐓟 𐒻𐓟")
// Returns 8

显式处理代理项对的代码Code that explicitly handles surrogate pairs

如果你的代码调用显式操作代理项码位的 Api,请考虑使用 Rune 类型,如以下方法:Consider using the Rune type if your code calls APIs that explicitly operate on surrogate code points, such as the following methods:

例如,下面的方法具有用于处理代理项 char 对的特殊逻辑:For example, the following method has special logic to deal with surrogate char pairs:

static void ProcessStringUseChar(string s)
{
    Console.WriteLine("Using char");

    for (int i = 0; i < s.Length; i++)
    {
        if (!char.IsSurrogate(s[i]))
        {
            Console.WriteLine($"Code point: {(int)(s[i])}");
        }
        else if (i + 1 < s.Length && char.IsSurrogatePair(s[i], s[i + 1]))
        {
            int codePoint = char.ConvertToUtf32(s[i], s[i + 1]);
            Console.WriteLine($"Code point: {codePoint}");
            i++; // so that when the loop iterates it's actually +2
        }
        else
        {
            throw new Exception("String was not well-formed UTF-16.");
        }
    }
}

如果此类代码使用 Rune,则更简单,如以下示例中所示:Such code is simpler if it uses Rune, as in the following example:

static void ProcessStringUseRune(string s)
{
    Console.WriteLine("Using Rune");

    for (int i = 0; i < s.Length;)
    {
        if (!Rune.TryGetRuneAt(s, i, out Rune rune))
        {
            throw new Exception("String was not well-formed UTF-16.");
        }

        Console.WriteLine($"Code point: {rune.Value}");
        i += rune.Utf16SequenceLength; // increment the iterator by the number of chars in this Rune
    }
}

何时不使用 RuneWhen not to use Rune

如果你的代码不需要使用 Rune 类型:You don't need to use the Rune type if your code:

  • 查找确切 char 匹配项Looks for exact char matches
  • 拆分已知 char 值上的字符串Splits a string on a known char value

如果代码为,则使用 Rune 类型可能会返回不正确的结果:Using the Rune type may return incorrect results if your code:

  • 计算 string 中显示字符的数量Counts the number of display characters in a string

查找确切 char 匹配项Look for exact char matches

下面的代码循环访问 string 查找特定字符,并返回第一个匹配项的索引。The following code iterates through a string looking for specific characters, returning the index of the first match. 在代码查找由单个 char表示的字符时,无需更改此代码即可使用 RuneThere's no need to change this code to use Rune, as the code is looking for characters that are represented by a single char.

int GetIndexOfFirstAToZ(string s)
{
    for (int i = 0; i < s.Length; i++)
    {
        char thisChar = s[i];
        if ('A' <= thisChar && thisChar <= 'Z')
        {
            return i; // found a match
        }
    }

    return -1; // didn't find 'A' - 'Z' in the input string
}

在已知 char 上拆分字符串Split a string on a known char

通常调用 string.Split 并使用分隔符(如 ' ' (空格)或 ',' (逗号)),如以下示例中所示:It's common to call string.Split and use delimiters such as ' ' (space) or ',' (comma), as in the following example:

string inputString = "🐂, 🐄, 🐆";
string[] splitOnSpace = inputString.Split(' ');
string[] splitOnComma = inputString.Split(',');

此处无需使用 Rune,因为该代码查找由单个 char表示的字符。There is no need to use Rune here, because the code is looking for characters that are represented by a single char.

计算 string 中显示字符的数量Count the number of display characters in a string

字符串中 Rune 实例的数目可能与显示字符串时所显示的用户可识别字符的数目不匹配。The number of Rune instances in a string might not match the number of user-perceivable characters shown when displaying the string.

由于 Rune 实例表示 Unicode 标量值,因此遵循unicode 文本分段指导原则的组件可以将 Rune 用作统计显示字符的构建基块。Since Rune instances represent Unicode scalar values, components that follow the Unicode text segmentation guidelines can use Rune as a building block for counting display characters.

StringInfo 类型可用于统计显示字符,但在 .net 以外的 .NET 实现中,它不会在所有方案中正确计数。The StringInfo type can be used to count display characters, but in implementations of .NET other than .NET 5 it doesn't count correctly in all scenarios.

有关详细信息,请参阅字形群集For more information, see Grapheme clusters.

如何实例化 RuneHow to instantiate a Rune

有多种方法可获取 Rune 实例。There are several ways to get a Rune instance. 可以使用构造函数直接从中创建 RuneYou can use a constructor to create a Rune directly from:

  • 码位。A code point.

    Rune a = new Rune(0x0061); // LATIN SMALL LETTER A
    Rune b = new Rune(0x10421); // DESERET CAPITAL LETTER ER
    
  • 单个 charA single char.

    Rune c = new Rune('a');
    
  • 代理项 char 对。A surrogate char pair.

    Rune d = new Rune('\ud83d', '\udd2e'); // U+1F52E CRYSTAL BALL
    

如果输入不表示有效的 Unicode 标量值,则所有构造函数都将引发 ArgumentExceptionAll of the constructors throw an ArgumentException if the input doesn't represent a valid Unicode scalar value.

对于不希望在失败时引发异常的调用方,可以使用 Rune.TryCreate 方法。There are Rune.TryCreate methods available for callers who don't want exceptions to be thrown on failure.

也可以从现有的输入序列中读取 Rune 的实例。Rune instances can also be read from existing input sequences. 例如,给定表示 UTF-16 数据的 ReadOnlySpan<char>Rune.DecodeFromUtf16 方法返回输入范围开始处的第一个 Rune 实例。For instance, given a ReadOnlySpan<char> that represents UTF-16 data, the Rune.DecodeFromUtf16 method returns the first Rune instance at the beginning of the input span. Rune.DecodeFromUtf8 方法的操作方式类似,接受表示 UTF-8 数据的 ReadOnlySpan<byte> 参数。The Rune.DecodeFromUtf8 method operates similarly, accepting a ReadOnlySpan<byte> parameter that represents UTF-8 data. 可以从跨度的末尾而不是在范围的开头读取等效的方法。There are equivalent methods to read from the end of the span instead of the beginning of the span.

Rune 的查询属性Query properties of a Rune

若要获取 Rune 实例的整数码位值,请使用 Rune.Value 属性。To get the integer code point value of a Rune instance, use the Rune.Value property.

Rune rune = new Rune('\ud83d', '\udd2e'); // U+1F52E CRYSTAL BALL
int codePoint = rune.Value; // = 128302 decimal (= 0x1F52E)

Rune 类型上还提供了许多 char 类型上可用的静态 Api。Many of the static APIs available on the char type are also available on the Rune type. 例如,Rune.IsWhiteSpaceRune.GetUnicodeCategoryChar.IsWhiteSpaceChar.GetUnicodeCategory 方法等效。For instance, Rune.IsWhiteSpace and Rune.GetUnicodeCategory are equivalents to Char.IsWhiteSpace and Char.GetUnicodeCategory methods. Rune 方法正确处理代理项对。The Rune methods correctly handle surrogate pairs.

下面的示例代码将 ReadOnlySpan<char> 作为输入,并从跨距的开头和末尾裁剪,每 Rune 不是字母或数字。The following example code takes a ReadOnlySpan<char> as input and trims from both the start and the end of the span every Rune that isn't a letter or a digit.

static ReadOnlySpan<char> TrimNonLettersAndNonDigits(ReadOnlySpan<char> span)
{
    // First, trim from the front.
    // If any Rune can't be decoded
    // (return value is anything other than "Done"),
    // or if the Rune is a letter or digit,
    // stop trimming from the front and
    // instead work from the end.
    while (Rune.DecodeFromUtf16(span, out Rune rune, out int charsConsumed) == OperationStatus.Done)
    {
        if (Rune.IsLetterOrDigit(rune))
        { break; }
        span = span[charsConsumed..];
    }

    // Next, trim from the end.
    // If any Rune can't be decoded,
    // or if the Rune is a letter or digit,
    // break from the loop, and we're finished.
    while (Rune.DecodeLastFromUtf16(span, out Rune rune, out int charsConsumed) == OperationStatus.Done)
    {
        if (Rune.IsLetterOrDigit(rune))
        { break; }
        span = span[..^charsConsumed];
    }

    return span;
}

charRune之间存在一些 API 差异。There are some API differences between char and Rune. 例如:For example:

Rune 转换为 UTF-8 或 UTF-16Convert a Rune to UTF-8 or UTF-16

由于 Rune 是 Unicode 标量值,因此可将其转换为 UTF-8、UTF-16 或 UTF-32 编码。Since a Rune is a Unicode scalar value, it can be converted to UTF-8, UTF-16, or UTF-32 encoding. Rune 类型具有到 UTF-8 和 UTF-16 的转换的内置支持。The Rune type has built-in support for conversion to UTF-8 and UTF-16.

Rune.EncodeToUtf16Rune 实例转换为 char 的实例。The Rune.EncodeToUtf16 converts a Rune instance to char instances. 若要查询将 Rune 实例转换为 UTF-16 而产生 char 实例的数目,请使用 Rune.Utf16SequenceLength 属性。To query the number of char instances that would result from converting a Rune instance to UTF-16, use the Rune.Utf16SequenceLength property. 对于 UTF-8 转换,存在类似的方法。Similar methods exist for UTF-8 conversion.

下面的示例将 Rune 实例转换为 char 的数组。The following example converts a Rune instance to a char array. 此代码假定 rune 变量中有 Rune 实例:The code assumes you have a Rune instance in the rune variable:

char[] chars = new char[rune.Utf16SequenceLength];
int numCharsWritten = rune.EncodeToUtf16(chars);

由于 string 是 UTF-16 字符的序列,因此下面的示例还将 Rune 实例转换为 UTF-16:Since a string is a sequence of UTF-16 chars, the following example also converts a Rune instance to UTF-16:

string theString = rune.ToString();

下面的示例将 Rune 实例转换为 UTF-8 字节数组:The following example converts a Rune instance to a UTF-8 byte array:

byte[] bytes = new byte[rune.Utf8SequenceLength];
int numBytesWritten = rune.EncodeToUtf8(bytes);

Rune.EncodeToUtf16Rune.EncodeToUtf8 方法返回已写入的实际元素数。The Rune.EncodeToUtf16 and Rune.EncodeToUtf8 methods return the actual number of elements written. 如果目标缓冲区太短而无法包含结果,它们将引发异常。They throw an exception if the destination buffer is too short to contain the result. 对于想要避免异常的调用方,还存在非引发 TryEncodeToUtf8EncodeToUtf16 方法。There are non-throwing TryEncodeToUtf8 and EncodeToUtf16 methods as well for callers who want to avoid exceptions.

.NET 中的 Rune 与其他语言Rune in .NET vs. other languages

Unicode 标准中未定义 "rune" 一词。The term "rune" is not defined in the Unicode Standard. 术语 "日期" 改回创建 utf-8The term dates back to the creation of UTF-8. 讨论涌现和 Ken Thompson 正在寻找一项术语来描述最终成为一个码位的内容。Rob Pike and Ken Thompson were looking for a term to describe what would eventually become known as a code point. 它们是在 "rune" 一词上结算的,而且在涌现的更高版本中,对中转编程语言的影响将会帮助 popularize。They settled on the term "rune", and Rob Pike's later influence over the Go programming language helped popularize the term.

但是,.NET Rune 类型不等同于 "中转 rune 类型。However, the .NET Rune type is not the equivalent of the Go rune type. 在 "开始" 中,rune 类型是int32的别名In Go, the rune type is an alias for int32. 中转 rune 用于表示 Unicode 码位,但它可以是任何32位值,其中包括代理项码位和不是合法 Unicode 码位的值。A Go rune is intended to represent a Unicode code point, but it can be any 32-bit value, including surrogate code points and values that are not legal Unicode code points.

对于其他编程语言中类似的类型,请参阅Rust 的基元 char 类型Swift Unicode.Scalar 类型,两者都表示 Unicode 标量值。For similar types in other programming languages, see Rust's primitive char type or Swift's Unicode.Scalar type, both of which represent Unicode scalar values. 它们提供类似于的功能。NET 的 Rune 类型,并且不允许对不是合法 Unicode 标量值的值进行实例化。They provide functionality similar to .NET's Rune type, and they disallow instantiation of values that are not legal Unicode scalar values.

构造函数

Rune(Char)

从提供的 UTF-16 代码单元中创建 RuneCreates a Rune from the provided UTF-16 code unit.

Rune(Char, Char)

从提供的 UTF-16 代理项对中创建 RuneCreates a Rune from the provided UTF-16 surrogate pair.

Rune(Int32)

从表示 Unicode 标量值的指定 32 位整数中创建 RuneCreates a Rune from the specified 32-bit integer that represents a Unicode scalar value.

Rune(UInt32)

从表示 Unicode 标量值的指定 32 位无符号整数中创建 RuneCreates a Rune from the specified 32-bit unsigned integer that represents a Unicode scalar value.

属性

IsAscii

获取一个值,该值指示与此 Rune 关联的标量值是否在 ASCII 编码范围内。Gets a value that indicates whether the scalar value associated with this Rune is within the ASCII encoding range.

IsBmp

获取一个值,该值指示与此 Rune 关联的标量值是否在 BMP 编码范围内。Gets a value that indicates whether the scalar value associated with this Rune is within the BMP encoding range.

Plane

获取包含此标量的 Unicode 平面(0 至 16,含 0 和 16)。Gets the Unicode plane (0 to 16, inclusive) that contains this scalar.

ReplacementChar

获取表示 Unicode 替换字符 U+FFFD 的 Rune 实例。Gets a Rune instance that represents the Unicode replacement character U+FFFD.

Utf16SequenceLength

获取表示此标量值所需的 UTF-16 序列的代码单元 (Char) 中的长度。Gets the length in code units (Char) of the UTF-16 sequence required to represent this scalar value.

Utf8SequenceLength

获取表示此标量值所需的 UTF-8 序列的代码单元中的长度。Gets the length in code units of the UTF-8 sequence required to represent this scalar value.

Value

获取整数形式的 Unicode 标量值。Gets the Unicode scalar value as an integer.

方法

CompareTo(Rune)

将当前实例与指定的 Rune 实例进行比较。Compares the current instance to the specified Rune instance.

DecodeFromUtf16(ReadOnlySpan<Char>, Rune, Int32)

在提供的 UTF-16 源缓冲区开始处解码 RuneDecodes the Rune at the beginning of the provided UTF-16 source buffer.

DecodeFromUtf8(ReadOnlySpan<Byte>, Rune, Int32)

在提供的 UTF-8 源缓冲区开始处解码 RuneDecodes the Rune at the beginning of the provided UTF-8 source buffer.

DecodeLastFromUtf16(ReadOnlySpan<Char>, Rune, Int32)

在提供的 UTF-16 源缓冲区结尾处解码 RuneDecodes the Rune at the end of the provided UTF-16 source buffer.

DecodeLastFromUtf8(ReadOnlySpan<Byte>, Rune, Int32)

在提供的 UTF-8 源缓冲区结尾处解码 RuneDecodes the Rune at the end of the provided UTF-8 source buffer.

EncodeToUtf16(Span<Char>)

将此 Rune 解码为 UTF-16 目标缓冲区。Encodes this Rune to a UTF-16 destination buffer.

EncodeToUtf8(Span<Byte>)

将此 Rune 解码为 UTF-8 目标缓冲区。Encodes this Rune to a UTF-8 destination buffer.

Equals(Object)

返回一个指示当前实例是否与指定对象相等的值。Returns a value that indicates whether the current instance and a specified object are equal.

Equals(Rune)

返回一个值,该值指示当前实例是否与指定的 rune 相等。Returns a value that indicates whether the current instance and a specified rune are equal.

GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetNumericValue(Rune)

获取与指定 rune 关联的数值。Gets the numeric value associated with the specified rune.

GetRuneAt(String, Int32)

获取在字符串中指定位置开始的 RuneGets the Rune that begins at a specified position in a string.

GetUnicodeCategory(Rune)

获取与指定 rune 关联的 Unicode 类别。Gets the Unicode category associated with the specified rune.

IsControl(Rune)

返回一个值,该值指示指定的 rune 是否属于控制字符类别。Returns a value that indicates whether the specified rune is categorized as a control character.

IsDigit(Rune)

返回一个值,该值指示指定的 rune 是否属于十进制数字类别。Returns a value that indicates whether the specified rune is categorized as a decimal digit.

IsLetter(Rune)

返回一个值,该值指示指定的 rune 是否属于字母类别。Returns a value that indicates whether the specified rune is categorized as a letter.

IsLetterOrDigit(Rune)

返回一个值,该值指示指定的 rune 属于字母类别还是十进制数字类别。Returns a value that indicates whether the specified rune is categorized as a letter or a decimal digit.

IsLower(Rune)

返回一个值,该值指示指定的 rune 是否属于小写字母类别。Returns a value that indicates whether the specified rune is categorized as a lowercase letter.

IsNumber(Rune)

返回一个值,该值指示指定的 rune 是否属于数字类别。Returns a value that indicates whether the specified rune is categorized as a number.

IsPunctuation(Rune)

返回一个值,该值指示指定的 rune 是否属于标点符号类别。Returns a value that indicates whether the specified rune is categorized as a punctuation mark.

IsSeparator(Rune)

返回一个值,该值指示指定的 rune 是否属于分隔符类别。Returns a value that indicates whether the specified rune is categorized as a separator character.

IsSymbol(Rune)

返回一个值,该值指示指定的 rune 是否属于符号字符类别。Returns a value that indicates whether the specified rune is categorized as a symbol character.

IsUpper(Rune)

返回一个值,该值指示指定的 rune 是否属于大写字母类别。Returns a value that indicates whether the specified rune is categorized as an uppercase letter.

IsValid(Int32)

返回一个值,该值指示 32 位带符号整数是否表示有效的 Unicode 标量值;即它在 [ U+0000..U+D7FF ](含首尾值)或 [ U+E000..U+10FFFF ](含首尾值)范围内。Returns a value that indicates whether a 32-bit signed integer represents a valid Unicode scalar value; that is, it is in the range [ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive.

IsValid(UInt32)

返回一个值,该值指示 32 位无符号整数是否表示有效的 Unicode 标量值;即它在 [ U+0000..U+D7FF ](含首尾值)或 [ U+E000..U+10FFFF ](含首尾值)范围内。Returns a value that indicates whether a 32-bit unsigned integer represents a valid Unicode scalar value; that is, it is in the range [ U+0000..U+D7FF ], inclusive, or [ U+E000..U+10FFFF ], inclusive.

IsWhiteSpace(Rune)

返回一个值,该值指示指定的 rune 是否属于空格字符类别。Returns a value that indicates whether the specified rune is categorized as a white space character.

ToLower(Rune, CultureInfo)

根据指定区域性的大小写规则返回指定 Rune 转换为小写形式的副本。Returns a copy of the specified Rune converted to lowercase, using the casing rules of the specified culture.

ToLowerInvariant(Rune)

根据固定区域性的大小写规则返回指定 Rune 转换为小写形式的副本。Returns a copy of the specified Rune converted to lowercase using the casing rules of the invariant culture.

ToString()

返回此 Rune 实例的字符串表示形式。Returns the string representation of this Rune instance.

ToUpper(Rune, CultureInfo)

根据指定区域性的大小写规则返回指定 Rune 转换为大写形式的副本。Returns a copy of the specified Rune converted to uppercase, using the casing rules of the specified culture.

ToUpperInvariant(Rune)

根据固定区域性的大小写规则返回指定 Rune 转换为大写形式的副本。Returns a copy of the specified Rune converted to uppercase using the casing rules of the invariant culture.

TryCreate(Char, Char, Rune)

尝试从指定的 UTF-16 代理项对中创建 Rune,并返回指示操作是否成功的值。Attempts to create a Rune from the specified UTF-16 surrogate pair and returns a value that indicates whether the operation was successful.

TryCreate(Char, Rune)

尝试从指定的字符中创建 Rune,并返回指示操作是否成功的值。Attempts to create a Rune from a specified character and returns a value that indicates whether the operation succeeded.

TryCreate(Int32, Rune)

尝试从表示 Unicode 标量值的指定带符号整数中创建 RuneAttempts to create a Rune from a specified signed integer that represents a Unicode scalar value.

TryCreate(UInt32, Rune)

尝试从表示 Unicode 标量值的指定 32 位无符号整数中创建 RuneAttempts to create a Rune from the specified 32-bit unsigned integer that represents a Unicode scalar value.

TryEncodeToUtf16(Span<Char>, Int32)

将此 Rune 解码为 UTF-16 编码目标缓冲区。Encodes this Rune to a UTF-16 encoded destination buffer.

TryEncodeToUtf8(Span<Byte>, Int32)

将此 Rune 解码为 UTF-8 编码目标缓冲区。Encodes this Rune to a UTF-8 encoded destination buffer.

TryGetRuneAt(String, Int32, Rune)

尝试获取在字符串的指定位置处开始的 Rune,并返回指示操作是否成功的值。Attempts to get the Rune that begins at a specified position in a string, and return a value that indicates whether the operation succeeded.

运算符

Equality(Rune, Rune)

返回一个值,该值指示两个 Rune 实例是否相等。Returns a value that indicates whether two Rune instances are equal.

Explicit(Char to Rune)

定义从 16 位 Unicode 字符到 Rune 的显式转换。Defines an explicit conversion of a 16-bit Unicode character to a Rune.

Explicit(Int32 to Rune)

定义从 32 位带符号整数到 Rune 的显式转换。Defines an explicit conversion of a 32-bit signed integer to a Rune.

Explicit(UInt32 to Rune)

定义从 32 位无符号整数到 Rune 的显式转换。Defines an explicit conversion of a 32-bit unsigned integer to a Rune.

GreaterThan(Rune, Rune)

返回一个值,该值指示指定的 Rune 是否大于另一个指定的 RuneReturns a value indicating whether a specified Rune is greater than another specified Rune.

GreaterThanOrEqual(Rune, Rune)

返回一个值,该值指示指定的 Rune 是否大于等于另一个指定的 RuneReturns a value indicating whether a specified Rune is greater than or equal to another specified Rune.

Inequality(Rune, Rune)

返回一个值,该值指示两个 Rune 实例是否具有不同的值。Returns a value that indicates whether two Rune instances have different values.

LessThan(Rune, Rune)

返回一个值,该值指示指定的 Rune 是否小于另一个指定的 RuneReturns a value indicating whether a specified Rune is less than another specified Rune.

LessThanOrEqual(Rune, Rune)

返回一个值,该值指示指定的 Rune 是小于还是等于另一个指定的 RuneReturns a value indicating whether a specified Rune is less than or equal to another specified Rune.

适用于