String.Contains Yöntem
Tanım
Aşırı Yüklemeler
| Contains(Char, StringComparison) |
Belirtilen karşılaştırma kurallarını kullanarak, belirtilen bir karakterin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified character occurs within this string, using the specified comparison rules. |
| Contains(Char) |
Bu dize içinde belirtilen bir karakterin oluşup oluşmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified character occurs within this string. |
| Contains(String) |
Belirtilen bir alt dizenin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified substring occurs within this string. |
| Contains(String, StringComparison) |
Belirtilen karşılaştırma kuralları kullanılarak, belirtilen bir dizenin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules. |
Contains(Char, StringComparison)
Belirtilen karşılaştırma kurallarını kullanarak, belirtilen bir karakterin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified character occurs within this string, using the specified comparison rules.
public:
bool Contains(char value, StringComparison comparisonType);
public bool Contains (char value, StringComparison comparisonType);
member this.Contains : char * StringComparison -> bool
Public Function Contains (value As Char, comparisonType As StringComparison) As Boolean
Parametreler
- value
- Char
Aranmaya yönelik karakter.The character to seek.
- comparisonType
- StringComparison
Karşılaştırmada kullanılacak kuralları belirten sabit listesi değerlerinden biri.One of the enumeration values that specifies the rules to use in the comparison.
Döndürülenler
truevalueparametresi bu dize içinde oluşursa, aksi durumda, false .true if the value parameter occurs within this string; otherwise, false.
Şunlara uygulanır
Contains(Char)
Bu dize içinde belirtilen bir karakterin oluşup oluşmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified character occurs within this string.
public:
bool Contains(char value);
public bool Contains (char value);
member this.Contains : char -> bool
Public Function Contains (value As Char) As Boolean
Parametreler
- value
- Char
Aranmaya yönelik karakter.The character to seek.
Döndürülenler
truevalueparametresi bu dize içinde oluşursa, aksi durumda, false .true if the value parameter occurs within this string; otherwise, false.
Açıklamalar
Bu yöntem bir sıra (büyük/küçük harfe duyarlı ve kültüre duyarlı olmayan) karşılaştırması gerçekleştirir.This method performs an ordinal (case-sensitive and culture-insensitive) comparison.
Şunlara uygulanır
Contains(String)
Belirtilen bir alt dizenin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified substring occurs within this string.
public:
bool Contains(System::String ^ value);
public bool Contains (string value);
member this.Contains : string -> bool
Public Function Contains (value As String) As Boolean
Parametreler
- value
- String
Aranacak dize.The string to seek.
Döndürülenler
truevalueparametresi bu dize içinde oluşursa veya value boş dizeyse (""); Aksi takdirde, false .true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.
Özel durumlar
value, null değeridir.value is null.
Örnekler
Aşağıdaki örnek, "Fox" dizesinin tanıdık bir teklifin alt dizesi olup olmadığını belirler.The following example determines whether the string "fox" is a substring of a familiar quotation. Dizede "Fox" bulunursa, başlangıç konumunu da görüntüler.If "fox" is found in the string, it also displays its starting position.
using namespace System;
int main()
{
String^ s1 = "The quick brown fox jumps over the lazy dog";
String^ s2 = "fox";
bool b = s1->Contains( s2 );
Console::WriteLine( "Is the string, s2, in the string, s1?: {0}", b );
if (b) {
int index = s1->IndexOf(s2);
if (index >= 0)
Console::WriteLine("'{0} begins at character position {1}",
s2, index + 1);
}
}
// This example displays the following output:
// 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True
// 'fox begins at character position 17
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b = s1.Contains(s2);
Console.WriteLine("'{0}' is in the string '{1}': {2}",
s2, s1, b);
if (b) {
int index = s1.IndexOf(s2);
if (index >= 0)
Console.WriteLine("'{0} begins at character position {1}",
s2, index + 1);
}
// This example displays the following output:
// 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True
// 'fox begins at character position 17
Class Example
Public Shared Sub Main()
Dim s1 As String = "The quick brown fox jumps over the lazy dog"
Dim s2 As String = "fox"
Dim b As Boolean = s1.Contains(s2)
Console.WriteLine("'{0}' is in the string '{1}': {2}",
s2, s1, b)
If b Then
Dim index As Integer = s1.IndexOf(s2)
If index >= 0 Then
Console.WriteLine("'{0} begins at character position {1}",
s2, index + 1)
End If
End If
End Sub
End Class
'
' This example displays the following output:
' 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True
' 'fox begins at character position 17
Açıklamalar
Bu yöntem bir sıra (büyük/küçük harfe duyarlı ve kültüre duyarlı olmayan) karşılaştırması gerçekleştirir.This method performs an ordinal (case-sensitive and culture-insensitive) comparison. Arama, bu dizenin ilk karakter konumunda başlar ve son karakter konumu boyunca devam eder.The search begins at the first character position of this string and continues through the last character position.
Kültüre duyarlı veya sıralı büyük/küçük harfe duyarsız karşılaştırma gerçekleştirmek için:To perform a culture-sensitive or ordinal case-insensitive comparison:
.NET Core 2,1 ve sonraki sürümlerinde: Contains(Char, StringComparison) bunun yerine aşırı yüklemeyi çağırın.On .NET Core 2.1 and later versions: Call the Contains(Char, StringComparison) overload instead.
.NET Framework: özel bir yöntem oluşturun.On .NET Framework: Create a custom method. Aşağıdaki örnekte bu tür bir yaklaşım gösterilmektedir.The following example illustrates one such approach. StringBir parametre içeren bir genişletme yöntemi tanımlar StringComparison ve belirtilen dize karşılaştırma biçimi kullanılırken bir dizenin alt dize içerip içermediğini gösterir.It defines a String extension method that includes a StringComparison parameter and indicates whether a string contains a substring when using the specified form of string comparison.
String s = "This is a string.";
String sub1 = "this";
Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1);
StringComparison comp = StringComparison.Ordinal;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));
comp = StringComparison.OrdinalIgnoreCase;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));
// The example displays the following output:
// Does 'This is a string.' contain 'this'?
// Ordinal: False
// OrdinalIgnoreCase: True
Public Module Example
Public Sub Main
Dim s As String = "This is a string."
Dim sub1 As String = "this"
Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1)
Dim comp As StringComparison = StringComparison.Ordinal
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp))
comp = StringComparison.OrdinalIgnoreCase
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp))
End Sub
End Module
' The example displays the following output:
' Does 'This is a string.' contain 'this'?
' Ordinal: False
' OrdinalIgnoreCase: True
Geçerli örnekteki alt dizenin konumu ile ilgileniyorsanız value , IndexOf ilk oluşumunun başlangıç konumunu almak için yöntemini çağırabilir veya LastIndexOf en son oluşumunun başlangıç konumunu almak için yöntemini çağırabilirsiniz.If you are interested in the position of the substring value in the current instance, you can call the IndexOf method to get the starting position of its first occurrence, or you can call the LastIndexOf method to get the starting position of its last occurrence. Örnek, bir dize örneğinde bir alt IndexOf(String) dize bulunursa yöntemine bir çağrı içerir.The example includes a call to the IndexOf(String) method if a substring is found in a string instance.
Ayrıca bkz.
Şunlara uygulanır
Contains(String, StringComparison)
Belirtilen karşılaştırma kuralları kullanılarak, belirtilen bir dizenin bu dize içinde olup olmadığını gösteren bir değer döndürür.Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules.
public:
bool Contains(System::String ^ value, StringComparison comparisonType);
public bool Contains (string value, StringComparison comparisonType);
member this.Contains : string * StringComparison -> bool
Public Function Contains (value As String, comparisonType As StringComparison) As Boolean
Parametreler
- value
- String
Aranacak dize.The string to seek.
- comparisonType
- StringComparison
Karşılaştırmada kullanılacak kuralları belirten sabit listesi değerlerinden biri.One of the enumeration values that specifies the rules to use in the comparison.
Döndürülenler
truevalueparametresi bu dize içinde oluşursa veya value boş dizeyse (""); Aksi takdirde, false .true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.