String.Length プロパティとは? わかりやすく解説

String.Length プロパティ

このインスタンス文字数取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

Length プロパティは、このインスタンス内の Char オブジェクトの数を返しますUnicode 文字の数ではありません。これは、1 つUnicode 文字複数Char表されることがあるためです。おのおのの Char ではなくおのおのの Unicode 文字対象に処理を行うには、System.Globalization.StringInfo クラス使用します

使用例使用例

Length プロパティコード例次に示します

' Sample for String.Length
Imports System

Class Sample
   Public Shared Sub Main()
      Dim str As String
 = "abcdefg"
      Console.WriteLine("1) The length of '{0}'
 is {1}", str, str.Length)
      Console.WriteLine("2) The length of '{0}'
 is {1}", "xyz", "xyz".Length)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'1) The length of 'abcdefg' is 7
'2) The length of 'xyz' is 3
'
// Sample for String.Length
using System;

class Sample 
{
    public static void Main()
 
    {
    string str = "abcdefg";
    Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length);
    Console.WriteLine("2) The length of '{0}' is {1}", "xyz",
 "xyz".Length);
    }
}
/*
This example produces the following results:
1) The length of 'abcdefg' is 7
2) The length of 'xyz' is 3
*/
// Sample for String::Length
using namespace System;
int main()
{
   String^ str = "abcdefg";
   Console::WriteLine( "1) The length of '{0}' is {1}", str, str->Length
 );
   Console::WriteLine( "2) The length of '{0}' is {1}", "xyz",
 ((String^)"xyz")->Length );
}

/*
This example produces the following results:
1) The length of 'abcdefg' is 7
2) The length of 'xyz' is 3
*/
// Sample for String.Length
import System.*;

class Sample
{
    public static void main(String[]
 args)
    {
        String str = "abcdefg";
        Console.WriteLine("1) The length of '{0}' is {1}", str, 
            (Int32)str.get_Length());
        Console.WriteLine("2) The length of '{0}' is {1}", "xyz",
 
            (Int32)"xyz".get_Length());
    } //main
} //Sample
/*
This example produces the following results:
1) The length of 'abcdefg' is 7
2) The length of 'xyz' is 3
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からString.Length プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からString.Length プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からString.Length プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「String.Length プロパティ」の関連用語

String.Length プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.Length プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS