Strings.Split(String, String, Int32, CompareMethod) Yöntem
Tanım
Belirtilen sayıda alt dize içeren sıfır tabanlı, tek boyutlu bir dizi döndürür.Returns a zero-based, one-dimensional array containing a specified number of substrings.
public static string[] Split (string? Expression, string? Delimiter = " ", int Limit = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static string[] Split (string Expression, string Delimiter = " ", int Limit = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member Split : string * string * int * Microsoft.VisualBasic.CompareMethod -> string[]
Public Function Split (Expression As String, Optional Delimiter As String = " ", Optional Limit As Integer = -1, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As String()
Parametreler
- Expression
- String
Gereklidir.Required. String alt dizeleri ve sınırlayıcıları içeren ifade.String expression containing substrings and delimiters.
- Delimiter
- String
İsteğe bağlı.Optional. Alt dize sınırlarını tanımlamak için kullanılan tek bir karakter.Any single character used to identify substring limits. DelimiterAtlanırsa, boşluk karakteri ("") sınırlayıcı olarak kabul edilir.If Delimiter is omitted, the space character (" ") is assumed to be the delimiter.
- Limit
- Int32
İsteğe bağlı.Optional. Giriş dizesinin bölünmesi gereken en fazla alt dize sayısı.Maximum number of substrings into which the input string should be split. Varsayılan,-1, giriş dizesinin dizenin her oluşumunda bölünmesi gerektiğini gösterir Delimiter .The default, -1, indicates that the input string should be split at every occurrence of the Delimiter string.
- Compare
- CompareMethod
İsteğe bağlı.Optional. Alt dizeleri değerlendirirken kullanılacak karşılaştırmayı gösteren sayısal değer.Numeric value indicating the comparison to use when evaluating substrings. Değerler için "Ayarlar"a bakın.See "Settings" for values.
Döndürülenler
- String[]
String dizide.String array. ExpressionSıfır uzunluklu bir dize ("") ise, Split sıfır uzunluklu dize içeren tek öğeli bir dizi döndürür.If Expression is a zero-length string (""), Split returns a single-element array containing a zero-length string. DelimiterSıfır uzunluklu bir dizeyse veya içinde herhangi bir yerde görünmezse Expression , Split tüm dizeyi içeren tek öğeli bir dizi döndürür Expression .If Delimiter is a zero-length string, or if it does not appear anywhere in Expression, Split returns a single-element array containing the entire Expression string.
Örnekler
Aşağıdaki örnek, bir dizenin boşluklarla nasıl bölüneceği gösterir.The following example demonstrates how to split a string at its spaces.
Dim testString As String = "Look at these!"
' Returns an array containing "Look", "at", and "these!".
Dim testArray() As String = Split(testString)
Aşağıdaki örnek, bir satırda birden çok sınırlayıcıya sahip dizelerin nasıl bölüneceği ve boş dizelerin filtreleneceğini gösterir.The following example demonstrates how to split strings with multiple delimiters in a row and filter out the empty strings.
Dim testString As String = "apple pear banana "
Dim testArray() As String = Split(testString)
' testArray holds {"apple", "", "", "", "pear", "banana", "", ""}
Dim lastNonEmpty As Integer = -1
For i As Integer = 0 To testArray.Length - 1
If testArray(i) <> "" Then
lastNonEmpty += 1
testArray(lastNonEmpty) = testArray(i)
End If
Next
ReDim Preserve testArray(lastNonEmpty)
' testArray now holds {"apple", "pear", "banana"}
Açıklamalar
Varsayılan olarak veya Limit eşittir-1 olduğunda, Split işlev sınırlayıcı dizenin her oluşumunda giriş dizesini böler ve bir dizideki alt dizeleri döndürür.By default, or when Limit equals -1, the Split function splits the input string at every occurrence of the delimiter string, and returns the substrings in an array. LimitParametre sıfırdan büyükse, Split işlevi Limit sınırlayıcıların ilk 1 tekrarında dizeyi böler ve sonuçta elde edilen alt dizeleri içeren bir dizi döndürür.When the Limit parameter is greater than zero, the Split function splits the string at the first Limit-1 occurrences of the delimiter, and returns an array with the resulting substrings. Örneğin, diziyi döndürür Split("a:b:c", ":") {"a", "b", "c"} , Split("a:b:c", ":", 2) dizi döndürür {"a", "b:c"} .For example, Split("a:b:c", ":") returns the array {"a", "b", "c"}, while Split("a:b:c", ":", 2) returns the array {"a", "b:c"}.
Splitİşlev bir satırda iki sınırlayıcı veya dizenin başlangıcında veya sonunda bir sınırlayıcı ile karşılaştığında, bunları boş bir dizeyi ("") çevreleyecek şekilde yorumlar.When the Split function encounters two delimiters in a row, or a delimiter at the beginning or end of the string, it interprets them as surrounding an empty string (""). Örneğin, Split("xx", "x") üç boş dize içeren diziyi döndürür: biri dizenin başlangıcı ve ilk "x" arasında, diğeri iki "x" dizesi arasında, diğeri ise son "x" ve dizenin sonu arasında.For example, Split("xx", "x") returns the array containing three empty strings: one from between the beginning of the string and the first "x", one from between the two "x" strings, and one from between the last "x" and the end of the string.
Bu tablo, isteğe bağlı Delimiter , Limit ve Compare parametrelerinin işlevin davranışını nasıl değiştirebileceğinizi gösterir Split .This table demonstrates how the optional Delimiter, Limit, and Compare parameters can change the behavior of the Split function.
| Çağrıyı BölSplit Call | Dönüş DeğeriReturn Value |
|---|---|
Split("42, 12, 19") |
{"42,", "12", "19"}{"42," , "12," , "19"} |
Split("42, 12, 19", ", ") |
{"42", "12", "19"}{"42", "12", "19"} |
Split("42, 12, 19", ", ", 2) |
{"42", "12, 19"}{"42", "12, 19"} |
Split("192.168.0.1", ".") |
{"192", "168", "0", "1"}{"192", "168", "0", "1"} |
Split("Alice and Bob", " AND ") |
{"Gamze ve Bob"}{"Alice and Bob"} |
Split("Alice and Bob", " AND ", ,CompareMethod.Text) |
{"Gamze", "Bob"}{"Alice", "Bob"} |
Split("someone@example.com", "@",1) |
{"someone@example.com"}{"someone@example.com"} |
Split("someone@example.com", "@",2) |
{"birisi", "example.com"}{"someone", "example.com"} |
CompareBağımsız değişkeni aşağıdaki değerlere sahip olabilir.The Compare argument can have the following values.
| SabitConstant | DescriptionDescription | DeğerValue |
|---|---|---|
CompareMethod.Binary |
İkili karşılaştırma yaparPerforms a binary comparison | 00 |
CompareMethod.Text |
Metinsel karşılaştırma yaparPerforms a textual comparison | 11 |