String クラス

String クラス (System 名前空間)

[APIドキュメント]

public sealed class String : ICloneable, IComparable, IComparable<string>, IConvertible, IEquatable<string>, IEnumerable<char>

継承:Object → String

  • テキストを一連の UTF-16 コード単位として表現します。

フィールド

Empty

@ [APIドキュメント]

public static readonly string Empty;

  • 長さゼロの文字列””を表します(nullとは異なります)

プロパティ

Length

@ [APIドキュメント]

public int Length { get; }

  • 現在の String オブジェクト内の文字数を取得します。

メソッド

IndexOf

@ [APIドキュメント]

public int IndexOf (string value, int startIndex, int count);
public int IndexOf (string value, int startIndex, int count, StringComparison comparisonType);
public int IndexOf (string value, int startIndex, StringComparison comparisonType);
public int IndexOf (char value, int startIndex, int count);
public int IndexOf (string value, StringComparison comparisonType);
public int IndexOf (char value, StringComparison comparisonType);
public int IndexOf (char value, int startIndex);
public int IndexOf (string value);
public int IndexOf (char value);
public int IndexOf (string value, int startIndex);

  • このインスタンス内で最初に出現する指定された文字(文字列)の 0 から始まるインデックスを返します。
  • 指定された文字(文字列)が見つかれない場合は、-1を返します。

IsNullOrEmpty

@ [APIドキュメント]

public static bool IsNullOrEmpty (string? value);

  • 指定された文字列が null または空の文字列 (“”) であるかどうかを示します。

IsNullOrWhiteSpace

@ [APIドキュメント]

public static bool IsNullOrWhiteSpace (string? value);

  • 指定された文字列が null または空であるか、空白文字だけで構成されているかどうかを示します。

LastIndexOf

@ [APIドキュメント]

public int LastIndexOf (string value, int startIndex, StringComparison comparisonType);
public int LastIndexOf (string value, int startIndex, int count);
public int LastIndexOf (char value, int startIndex, int count);
public int LastIndexOf (string value, StringComparison comparisonType);
public int LastIndexOf (char value);
public int LastIndexOf (char value, int startIndex);
public int LastIndexOf (string value);
public int LastIndexOf (string value, int startIndex, int count, StringComparison comparisonType);
public int LastIndexOf (string value, int startIndex);

  • このインスタンス内で最後に出現する指定 Unicode 文字または文字列の 0 から始まるインデックス位置をレポートします。
  • このインスタンス内で文字または文字列が見つからない場合、このメソッドは -1 を返します。

Remove

@ [APIドキュメント]

public string Remove (int startIndex);
public string Remove (int startIndex, int count);

  • startIndexで指定された位置から最後まで、もしくは指定された文字数を削除した新しい文字列を返します。

Split

@ [APIドキュメント]

public string[] Split (char[]? separator, int count, StringSplitOptions options);
public string[] Split (char separator, int count, StringSplitOptions options = System.StringSplitOptions.None);
public string[] Split (string[]? separator, int count, StringSplitOptions options);
public string[] Split (string[]? separator, StringSplitOptions options);
public string[] Split (string? separator, int count, StringSplitOptions options = System.StringSplitOptions.None);
public string[] Split (char[]? separator, StringSplitOptions options);
public string[] Split (char[]? separator, int count);
public string[] Split (char separator, StringSplitOptions options = System.StringSplitOptions.None);
public string[] Split (string? separator, StringSplitOptions options = System.StringSplitOptions.None);
public string[] Split (params char[]? separator);

  • 区切り記号の配列内の文字に基づいて文字列を部分文字列に分割します。

StartsWith

@ [APIドキュメント]

public bool StartsWith (char value);
public bool StartsWith (string value);
public bool StartsWith (string value, StringComparison comparisonType);
public bool StartsWith (string value, bool ignoreCase, System.Globalization.CultureInfo? culture);

  • この文字列インスタンスが指定した文字(文字列)で始まっているかどうかを判断します。

Substring

@ [APIドキュメント]

public string Substring (int startIndex);
public string Substring (int startIndex, int length);

  • インスタンスから部分文字列を取得します。

ToLower

@ [APIドキュメント]

public string ToLower ();
public string ToLower (CultureInfo? culture);

  • この文字列のコピーを小文字に変換して返します。

ToUpper

@ [APIドキュメント]

public string ToUpper ();
public string ToUpper (CultureInfo? culture);

  • この文字列のコピーを大文字に変換して返します。

Trim

@ [APIドキュメント]

public string Trim (params char[]? trimChars);
public string Trim (char trimChar);
public string Trim ();

  • 現在の文字列の先頭・末尾から、指定した文字を削除した新しい文字列を返します。
  • 引数に何も指定しない場合は、現在の文字列の先頭・末尾から空白文字をすべて削除します。