String.CompareOrdinal メソッド (String, String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim strA As String Dim strB As String Dim returnValue As Integer returnValue = String.CompareOrdinal(strA, strB)
- strB
第 2 の String。
2 つの比較対象値の関係を示す整数値。

このメソッドは、序数の並べ替え規則を使用して大文字と小文字を区別する比較を実行します。単語、文字列、序数の並べ替えの詳細については、「System.Globalization.CompareOptions」を参照してください。

大文字と小文字の表記だけが異なる 2 つの文字列について、序数ベースの比較を実行するコード例を次に示します。
' Sample for String.CompareOrdinal(String, String) Imports System Imports Microsoft.VisualBasic Class Sample Public Shared Sub Main() Dim str1 As [String] = "ABCD" Dim str2 As [String] = "abcd" Dim str As [String] Dim result As Integer Console.WriteLine() Console.WriteLine("Compare the numeric values of the corresponding Char objects in each string.") Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2) result = [String].CompareOrdinal(str1, str2) str = IIf(result < 0, "less than", IIf(result > 0, "greater than", "equal to")) Console.Write("String '{0}' is ", str1) Console.Write("{0} ", str) Console.WriteLine("String '{0}'.", str2) End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' 'Compare the numeric values of the corresponding Char objects in each string. 'str1 = 'ABCD', str2 = 'abcd' 'String 'ABCD' is less than String 'abcd'. '
// Sample for String.CompareOrdinal(String, String) using System; class Sample { public static void Main() { String str1 = "ABCD"; String str2 = "abcd"; String str; int result; Console.WriteLine(); Console.WriteLine("Compare the numeric values of the corresponding Char objects in each string."); Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2); result = String.CompareOrdinal(str1, str2); str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to")); Console.Write("String '{0}' is ", str1); Console.Write("{0} ", str); Console.WriteLine("String '{0}'.", str2); } } /* This example produces the following results: Compare the numeric values of the corresponding Char objects in each string. str1 = 'ABCD', str2 = 'abcd' String 'ABCD' is less than String 'abcd'. */
// Sample for String::CompareOrdinal(String, String) using namespace System; int main() { String^ str1 = "ABCD"; String^ str2 = "abcd"; String^ str; int result; Console::WriteLine(); Console::WriteLine( "Compare the numeric values of the corresponding Char objects in each string." ); Console::WriteLine( "str1 = '{0}', str2 = '{1}'", str1, str2 ); result = String::CompareOrdinal( str1, str2 ); str = ((result < 0) ? "less than" : ((result > 0) ? (String^)"greater than" : "equal to")); Console::Write( "String '{0}' is ", str1 ); Console::Write( "{0} ", str ); Console::WriteLine( "String '{0}'.", str2 ); } /* This example produces the following results: Compare the numeric values of the corresponding Char objects in each string. str1 = 'ABCD', str2 = 'abcd' String 'ABCD' is less than String 'abcd'. */
// Sample for String.CompareOrdinal(String, String) import System.*; class Sample { public static void main(String[] args) { String str1 = "ABCD"; String str2 = "abcd"; String str; int result; Console.WriteLine(); Console.WriteLine("Compare the numeric values of the corresponding " + "Char objects in each string."); Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2); result = String.CompareOrdinal(str1, str2); str = result < 0 ? "less than" : (result > 0) ? "greater than" : "equal to"; Console.Write("String '{0}' is ", str1); Console.Write("{0} ", str); Console.WriteLine("String '{0}'.", str2); } //main } //Sample /* This example produces the following results: Compare the numeric values of the corresponding Char objects in each string. str1 = 'ABCD', str2 = 'abcd' String 'ABCD' is less than String 'abcd'. */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.CompareOrdinal メソッド (String, Int32, String, Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function CompareOrdinal ( _ strA As String, _ indexA As Integer, _ strB As String, _ indexB As Integer, _ length As Integer _ ) As Integer
Dim strA As String Dim indexA As Integer Dim strB As String Dim indexB As Integer Dim length As Integer Dim returnValue As Integer returnValue = String.CompareOrdinal(strA, indexA, strB, indexB, length)
public: static int CompareOrdinal ( String^ strA, int indexA, String^ strB, int indexB, int length )
public static function CompareOrdinal ( strA : String, indexA : int, strB : String, indexB : int, length : int ) : int
- strB
第 2 の String。
2 つの比較対照値の構文上の関係を示す 32 ビット符号付き整数。


indexA、indexB、および length の各パラメータが負数以外である必要があります。
比較される文字数は、strA から indexA を引いた長さ、strB から indexB を引いた長さ、および length のうちで一番小さい値になります。
このメソッドは、序数の並べ替え規則を使用して大文字と小文字を区別する比較を実行します。単語、文字列、序数の並べ替えの詳細については、「System.Globalization.CompareOptions」を参照してください。

CompareOrdinal と Compare が異なる並べ替え順序を使用することを、次のコード例に示します。
Imports System Imports System.Globalization Class Test Public Shared Sub Main(args() As [String]) Dim strLow As [String] = "abc" Dim strCap As [String] = "ABC" Dim result As [String] = "equal to " Dim x As Integer = 0 Dim pos As Integer = 1 ' The Unicode codepoint for 'b' is greater than the codepoint for 'B'. x = [String].CompareOrdinal(strLow, pos, strCap, pos, 1) If x < 0 Then result = "less than" End If If x > 0 Then result = "greater than" End If ' In U.S. English culture, 'b' is linguistically less than 'B'. Console.WriteLine("CompareOrdinal(""{0}"".Chars({2}), ""{1}"".Chars({2})):", strLow, strCap, pos) Console.WriteLine(" '{0}' is {1} '{2}'", strLow.Chars(pos), result, strCap.Chars(pos)) x = [String].Compare(strLow, pos, strCap, pos, 1, False, New CultureInfo("en-US")) If x < 0 Then result = "less than" ElseIf x > 0 Then result = "greater than" End If Console.WriteLine("Compare(""{0}"".Chars({2}), ""{1}"".Chars({2})):", strLow, strCap, pos) Console.WriteLine(" '{0}' is {1} '{2}'", strLow.Chars(pos), result, strCap.Chars(pos)) End Sub 'Main End Class 'Test
using System; using System.Globalization; class Test { public static void Main(String[] args) { String strLow = "abc"; String strCap = "ABC"; String result = "equal to "; int x = 0; int pos = 1; // The Unicode codepoint for 'b' is greater than the codepoint for 'B'. x = String.CompareOrdinal(strLow, pos, strCap, pos, 1); if (x < 0) result = "less than"; if (x > 0) result = "greater than"; Console.WriteLine("CompareOrdinal(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, pos); Console.WriteLine(" '{0}' is {1} '{2}'", strLow[pos], result, strCap[pos]); // In U.S. English culture, 'b' is linguistically less than 'B'. x = String.Compare(strLow, pos, strCap, pos, 1, false, new CultureInfo("en-US")); if (x < 0) result = "less than"; else if (x > 0) result = "greater than"; Console.WriteLine("Compare(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, pos); Console.WriteLine(" '{0}' is {1} '{2}'", strLow[pos], result, strCap[pos]); } }
using namespace System; using namespace System::Globalization; int main() { String^ strLow = "abc"; String^ strCap = "ABC"; String^ result = "equal to "; int x = 0; int pos = 1; // The Unicode codepoint for 'b' is greater than the codepoint for 'B'. x = String::CompareOrdinal( strLow, pos, strCap, pos, 1 ); if ( x < 0 ) result = "less than"; if ( x > 0 ) result = "greater than"; Console::WriteLine( "CompareOrdinal(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, pos ); Console::WriteLine( " '{0}' is {1} '{2}'", strLow[ pos ], result, strCap[ pos ] ); // In U.S. English culture, 'b' is linguistically less than 'B'. x = String::Compare( strLow, pos, strCap, pos, 1, false, gcnew CultureInfo( "en-US" ) ); if ( x < 0 ) result = "less than"; else if ( x > 0 ) result = "greater than"; Console::WriteLine( "Compare(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, pos ); Console::WriteLine( " '{0}' is {1} '{2}'", strLow[ pos ], result, strCap[ pos ] ); }
import System.*; import System.Globalization.*; class Test { public static void main(String[] args) { String strLow = "abc"; String strCap = "ABC"; String result = "equal to "; int x = 0; int pos = 1; // The Unicode codepoint for 'b' is greater than the codepoint for 'B'. x = String.CompareOrdinal(strLow, pos, strCap, pos, 1); if (x < 0) { result = "less than"; } if (x > 0) { result = "greater than"; } Console.WriteLine("CompareOrdinal(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, (Int32)pos); Console.WriteLine(" '{0}' is {1} '{2}'", (System.Char)strLow.charAt(pos), result, (System.Char)strCap.charAt(pos)); // In U.S. English culture, 'b' is linguistically less than 'B'. x = String.Compare(strLow, pos, strCap, pos, 1, false, new CultureInfo("en-US")); if (x < 0) { result = "less than"; } else { if (x > 0) { result = "greater than"; } } Console.WriteLine("Compare(\"{0}\"[{2}], \"{1}\"[{2}]):", strLow, strCap, (Int32)pos); Console.WriteLine(" '{0}' is {1} '{2}'", (System.Char)strLow.charAt(pos), result, (System.Char)strCap.charAt(pos)); } //main } //Test

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.CompareOrdinal メソッド

名前 | 説明 |
---|---|
String.CompareOrdinal (String, String) | それぞれの文字列の対応する Char オブジェクトの数値を評価することで、指定した 2 つの String を比較します。 .NET Compact Framework によってサポートされています。 |
String.CompareOrdinal (String, Int32, String, Int32, Int32) | それぞれの部分文字列の対応する Char オブジェクトの数値を評価することで、指定した 2 つの String を比較します。 .NET Compact Framework によってサポートされています。 |

Weblioに収録されているすべての辞書からString.CompareOrdinalを検索する場合は、下記のリンクをクリックしてください。

- String.CompareOrdinalのページへのリンク