このインスタンスの文字数を取得します。
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
Public ReadOnly Property Length As Integer
Dim instance As String
Dim value As Integer
value = instance.Length
public int Length { get; }
public:
property int Length {
int get ();
}
/** @property */
public int get_Length ()
public function get Length () : int
プロパティ値
このインスタンスの文字数。
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
*/
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0