From 7a29682dc2bb506d4f69878b69bb152c7341d5de Mon Sep 17 00:00:00 2001 From: WilliamAntonRohm Date: Fri, 23 Aug 2019 16:20:31 -0700 Subject: [PATCH] copy of final reviewed doc --- xml/System/String.xml | 291 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 235 insertions(+), 56 deletions(-) diff --git a/xml/System/String.xml b/xml/System/String.xml index b9753bd4acf..e6974ad46e8 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -1,4 +1,4 @@ - + @@ -1301,6 +1301,38 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + + + + + + + Property + + System.Runtime + 4.2.1.0 + + + mscorlib + + + netstandard + 2.1.0.0 + + + System.Char + + + + + + To be added. + To be added. + To be added. + To be added. + + @@ -1376,6 +1408,38 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ + + + + + + + + Property + + System.Runtime + 4.2.1.0 + + + mscorlib + + + netstandard + 2.1.0.0 + + + System.String + + + + + + To be added. + To be added. + To be added. + To be added. + + @@ -1450,6 +1514,8 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ > [!WARNING] > Whenever possible, you should call an overload of the method that includes a parameter. For more information, see [Best Practices for Using Strings](~/docs/standard/base-types/best-practices-strings.md). + [!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)] + ]]> Best Practices for Using Strings in the .NET Framework @@ -1552,7 +1618,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The following example calls the method to compare three sets of strings. [!code-cpp[System.String.Compare#18](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp#18)] - [!code-csharp[System.String.Compare#18](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs#18)] + [!code-csharp-interactive[System.String.Compare#18](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs#18)] [!code-vb[System.String.Compare#18](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb#18)] In the following example, the `ReverseStringComparer` class demonstrates how you can evaluate two strings with the method. @@ -1671,10 +1737,11 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ ## Examples + The following example demonstrates that the method is equivalent to using or when comparing strings. [!code-cpp[System.String.Compare#18](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp#18)] - [!code-csharp[System.String.Compare#18](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs#18)] + [!code-csharp-interactive[System.String.Compare#18](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs#18)] [!code-vb[System.String.Compare#18](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb#18)] ]]> @@ -2124,7 +2191,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The following example compares two substrings. [!code-cpp[string.compare3#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.compare3/CPP/comp3.cpp#1)] - [!code-csharp[string.compare3#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare3/CS/comp3.cs#1)] + [!code-csharp-interactive[string.compare3#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare3/CS/comp3.cs#1)] [!code-vb[string.compare3#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.compare3/VB/comp3.vb#1)] ]]> @@ -2252,7 +2319,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The following example performs two comparisons of two substrings that only differ in case. The first comparison ignores case and the second comparison considers case. [!code-cpp[string.compare4#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.compare4/CPP/comp4.cpp#1)] - [!code-csharp[string.compare4#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare4/CS/comp4.cs#1)] + [!code-csharp-interactive[string.compare4#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare4/CS/comp4.cs#1)] [!code-vb[string.compare4#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.compare4/VB/comp4.vb#1)] ]]> @@ -2382,7 +2449,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The following example compares two substrings. [!code-cpp[string.compare3#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.compare3/CPP/comp3.cpp#1)] - [!code-csharp[string.compare3#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare3/CS/comp3.cs#1)] + [!code-csharp-interactive[string.compare3#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.compare3/CS/comp3.cs#1)] [!code-vb[string.compare3#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.compare3/VB/comp3.vb#1)] ]]> @@ -4011,8 +4078,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The character to seek. Returns a value indicating whether a specified character occurs within this string. - - if the parameter occurs within this string; otherwise, . + if the parameter occurs within this string; otherwise, . To be added. @@ -4058,8 +4124,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The string to seek. Returns a value indicating whether a specified substring occurs within this string. - - if the parameter occurs within this string, or if is the empty string (""); otherwise, . + if the parameter occurs within this string, or if is the empty string (""); otherwise, . extension method that includes a parameter and indicates whether a string contains a substring when using the specified form of string comparison. - + [!code-csharp[System.String.Contains#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Contains/cs/ContainsExt1.cs#1)] [!code-vb[System.String.Contains#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Contains/vb/ContainsExt1.vb#1)] @@ -4081,10 +4146,13 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ ## Examples + + [!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)] + The following example determines whether the string "fox" is a substring of a familiar quotation. If "fox" is found in the string, it also displays its starting position. [!code-cpp[String.Contains#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.contains/CPP/cont.cpp#1)] - [!code-csharp[String.Contains#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs#1)] + [!code-csharp-interactive[String.Contains#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs#1)] [!code-vb[String.Contains#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.contains/VB/cont.vb#1)] ]]> @@ -4125,8 +4193,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The character to seek. One of the enumeration values that specifies the rules to use in the comparison. Returns a value indicating whether a specified character occurs within this string, using the specified comparison rules. - - if the parameter occurs within this string; otherwise, . + if the parameter occurs within this string; otherwise, . To be added. @@ -4160,8 +4227,7 @@ You can download the [Sorting Weight Tables](https://www.microsoft.com/download/ The string to seek. One of the enumeration values that specifies the rules to use in the comparison. Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules. - - if the parameter occurs within this string, or if is the empty string (""); otherwise, . + if the parameter occurs within this string, or if is the empty string (""); otherwise, . To be added. @@ -6439,6 +6505,15 @@ The `GetPinnableReference` method returns a character that can be used for pinni Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance. + + + @@ -6492,14 +6567,12 @@ The `GetPinnableReference` method returns a character that can be used for pinni Index numbering starts from zero. This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - - - + ## Examples The following example demonstrates how you can search a for a character using the method. [!code-cpp[System.String.IndexOf#5](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/indexof_c.cpp#5)] - [!code-csharp[System.String.IndexOf#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs#5)] + [!code-csharp-interactive[System.String.IndexOf#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs#5)] [!code-vb[System.String.IndexOf#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/indexof_c.vb#5)] ]]> @@ -6559,16 +6632,15 @@ The `GetPinnableReference` method returns a character that can be used for pinni Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. If `value` consists only of one or more ignorable characters, the method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the [!INCLUDE[netfx40_short](~/includes/netfx40-short-md.md)] or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in `value`. When searching for a soft hyphen only, the method returns 0 (zero) to indicate that it has found a match at the beginning of the string. - [!code-csharp[System.String.IndexOf#21](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs#21)] + [!code-csharp-interactive[System.String.IndexOf#21](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs#21)] [!code-vb[System.String.IndexOf#21](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable21.vb#21)] - - + ## Examples The following example searches for the "n" in "animal". Because string indexes begin at zero rather than one, the method indicates that the "n" is at position 1. [!code-cpp[System.String.IndexOf#12](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/simple1.cpp#12)] - [!code-csharp[System.String.IndexOf#12](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs#12)] + [!code-csharp-interactive[System.String.IndexOf#12](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs#12)] [!code-vb[System.String.IndexOf#12](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/simple1.vb#12)] The following example uses the method to determine the starting position of an animal name in a sentence. It then uses this position to insert an adjective that describes the animal into the sentence. @@ -6653,7 +6725,7 @@ The `GetPinnableReference` method returns a character that can be used for pinni The following example demonstrates the method. [!code-cpp[string.indexof1#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.indexof1/CPP/ixof1.cpp#1)] - [!code-csharp[string.indexof1#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.indexof1/CS/ixof1.cs#1)] + [!code-csharp-interactive[string.indexof1#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.indexof1/CS/ixof1.cs#1)] [!code-vb[string.indexof1#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.indexof1/VB/ixof1.vb#1)] ]]> @@ -7020,7 +7092,7 @@ The `comparisonType` parameter is a enumeration m The following example finds the index of all occurrences of the string "he" within a substring of another string. Note that the number of characters to be searched must be recalculated for each search iteration. [!code-cpp[string.indexof8#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.indexof8/CPP/ixof8.cpp#1)] - [!code-csharp[string.indexof8#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.indexof8/CS/ixof8.cs#1)] + [!code-csharp-interactive[string.indexof8#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.indexof8/CS/ixof8.cs#1)] [!code-vb[string.indexof8#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.indexof8/VB/ixof8.vb#1)] ]]> @@ -7919,17 +7991,17 @@ The `comparisonType` parameter is a enumeration m is a convenience method that enables you to simultaneously test whether a is `null` or its value is . It is equivalent to the following code: [!code-cpp[System.String.IsNullOrEmpty#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/isnullorempty1.cpp#1)] - [!code-csharp[System.String.IsNullOrEmpty#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/isnullorempty1.cs#1)] + [!code-csharp-interactive[System.String.IsNullOrEmpty#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/isnullorempty1.cs#1)] [!code-vb[System.String.IsNullOrEmpty#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/isnullorempty1.vb#1)] You can use the method to test whether a string is `null`, its value is , or it consists only of white-space characters. - + ## What is a null string? A string is `null` if it has not been assigned a value (in C++ and Visual Basic) or if it has explicitly been assigned a value of `null`. Although the [composite formatting](~/docs/standard/base-types/composite-formatting.md) feature can gracefully handle a null string, as the following example shows, attempting to call one if its members throws a . [!code-cpp[System.String.IsNullOrEmpty#2](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp#2)] -[!code-csharp[System.String.IsNullOrEmpty#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs#2)] +[!code-csharp-interactive[System.String.IsNullOrEmpty#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs#2)] [!code-vb[System.String.IsNullOrEmpty#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb#2)] ## What is an empty string? @@ -7937,14 +8009,17 @@ A string is `null` if it has not been assigned a value (in C++ and Visual Basic) A string is empty if it is explicitly assigned an empty string ("") or . An empty string has a of 0. The following example creates an empty string and displays its value and its length. [!code-cpp[System.String.IsNullOrEmpty#3](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp#3)] -[!code-csharp[System.String.IsNullOrEmpty#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs#3)] +[!code-csharp-interactive[System.String.IsNullOrEmpty#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs#3)] [!code-vb[System.String.IsNullOrEmpty#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb#3)] ## Examples + +[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)] + The following example examines three strings and determines whether each string has a value, is an empty string, or is `null`. [!code-cpp[String.IsNullOrEmpty#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.isNullOrEmpty/CPP/inoe.cpp#1)] - [!code-csharp[String.IsNullOrEmpty#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.isNullOrEmpty/CS/inoe.cs#1)] + [!code-csharp-interactive[String.IsNullOrEmpty#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.isNullOrEmpty/CS/inoe.cs#1)] [!code-vb[String.IsNullOrEmpty#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.isNullOrEmpty/VB/inoe.vb#1)] ]]> @@ -8022,6 +8097,15 @@ A string is empty if it is explicitly assigned an empty string ("") or Concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. + + + @@ -8157,7 +8241,7 @@ A string is empty if it is explicitly assigned an empty string ("") or ) is used instead. If any member of `values` is `null`, an empty string is used instead. is a convenience method that lets you concatenate each element in an `IEnumerable(Of String)` collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a `List(Of String)` object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The `IEnumerable(Of String)` collection returned by the method is passed to the method to display the result as a single string. - + [!code-csharp[System.String.Join#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.join/cs/join4.cs#4)] [!code-vb[System.String.Join#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join4.vb#4)] @@ -8249,7 +8333,7 @@ A string is empty if it is explicitly assigned an empty string ("") or If the first element of is , the method does not concatenate the elements in but instead returns . A number of workarounds for this issue are available. The easiest is to assign a value of to the first element of the array, as the following example shows. - [!code-csharp[System.String.Join#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.join/cs/joinfix1.cs#6)] + [!code-csharp-interactive[System.String.Join#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.join/cs/joinfix1.cs#6)] [!code-vb[System.String.Join#6](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/joinfix1.vb#6)] @@ -8433,7 +8517,7 @@ A string is empty if it is explicitly assigned an empty string ("") or @@ -9619,16 +9703,19 @@ A string is empty if it is explicitly assigned an empty string ("") or property returns 7, which indicates that it includes the six alphabetic characters as well as the null character. [!code-cpp[System.String.Class#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/system.string.class.cpp#1)] - [!code-csharp[System.String.Class#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Class/cs/System.String.Class.cs#1)] + [!code-csharp-interactive[System.String.Class#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Class/cs/System.String.Class.cs#1)] [!code-vb[System.String.Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/System.String.Class.vb#1)] ## Examples + +[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)] + The following example demonstrates the property. [!code-cpp[string.length#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.length/CPP/length.cpp#1)] - [!code-csharp[string.length#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs#1)] + [!code-csharp-interactive[string.length#1](~/samples/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs#1)] [!code-vb[string.length#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/string.length/VB/length.vb#1)] ]]> @@ -10448,6 +10535,15 @@ A string is empty if it is explicitly assigned an empty string ("") or Returns a new string in which all occurrences of a specified Unicode character or in the current string are replaced with another specified Unicode character or . + + + @@ -10507,7 +10603,7 @@ A string is empty if it is explicitly assigned an empty string ("") or method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - [!code-csharp[System.String.Replace#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs#2)] + [!code-csharp-interactive[System.String.Replace#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs#2)] [!code-vb[System.String.Replace#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace2.vb#2)] @@ -10516,7 +10612,7 @@ A string is empty if it is explicitly assigned an empty string ("") or @@ -10593,16 +10689,16 @@ A string is empty if it is explicitly assigned an empty string ("") or method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - [!code-csharp[System.String.Replace#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs#1)] + [!code-csharp-interactive[System.String.Replace#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs#1)] [!code-vb[System.String.Replace#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb#1)] ## Examples The following example demonstrates how you can use the method to correct a spelling error. - + [!code-cpp[stringreplace#1](~/samples/snippets/cpp/VS_Snippets_CLR/stringreplace/CPP/stringreplace.cpp#1)] - [!code-csharp[stringreplace#1](~/samples/snippets/csharp/VS_Snippets_CLR/stringreplace/CS/stringreplace.cs#1)] + [!code-csharp-interactive[stringreplace#1](~/samples/snippets/csharp/VS_Snippets_CLR/stringreplace/CS/stringreplace.cs#1)] [!code-vb[stringreplace#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/stringreplace/VB/stringreplace.vb#1)] ]]> @@ -11134,6 +11230,7 @@ A string is empty if it is explicitly assigned an empty string ("") or enumeration to include or exclude substrings generated by the method. [!code-cpp[string.split3#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp#1)] @@ -11421,6 +11518,7 @@ A string is empty if it is explicitly assigned an empty string ("") or enumeration to include or exclude substrings generated by the method. [!code-cpp[string.split3#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp#1)] @@ -11569,6 +11667,7 @@ A string is empty if it is explicitly assigned an empty string ("") or enumeration to include or exclude substrings generated by the method. [!code-cpp[string.split3#1](~/samples/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp#1)] @@ -11854,8 +11953,49 @@ A string is empty if it is explicitly assigned an empty string ("") or Retrieves a substring from this instance. This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list. + + + + + + + + + + + Method + + System.Runtime + 4.2.1.0 + + + mscorlib + + + netstandard + 2.1.0.0 + + + System.String + + + + + + To be added. + To be added. + To be added. + To be added. + + @@ -11913,17 +12053,16 @@ A string is empty if it is explicitly assigned an empty string ("") or method to separate key/value pairs that are delimited by an equals ("=") character. - [!code-csharp[System.String.Substring#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs#1)] + [!code-csharp-interactive[System.String.Substring#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs#1)] [!code-vb[System.String.Substring#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb#1)] The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. @@ -11942,6 +12081,37 @@ A string is empty if it is explicitly assigned an empty string ("") or + + + + + + + Method + + System.Runtime + 4.2.1.0 + + + mscorlib + + + netstandard + 2.1.0.0 + + + System.String + + + + + + To be added. + To be added. + To be added. + To be added. + + @@ -12008,12 +12178,12 @@ A string is empty if it is explicitly assigned an empty string ("") or or method. The following example extracts a continuous block of "b" characters from a string. - [!code-csharp[System.String.Substring#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs#2)] + [!code-csharp-interactive[System.String.Substring#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs#2)] [!code-vb[System.String.Substring#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring2.vb#2)] - If you've searched for multiple characters that are to mark the end of the substring, the `length` parameter equals `endIndex` + `endMatchLength` - `startIndex`, where `endIndex` is the return value of the or method, and `endMatchLength` is the length of the character sequence that marks the end of the substring. The following example extracts a block of text that contains an XML `` element. - [!code-csharp[System.String.Substring#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs#3)] + [!code-csharp-interactive[System.String.Substring#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs#3)] [!code-vb[System.String.Substring#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring3.vb#3)] - If the character or character sequence is not included in the end of the substring, the `length` parameter equals `endIndex` - `startIndex`, where `endIndex` is the return value of the or method. @@ -12025,7 +12195,7 @@ A string is empty if it is explicitly assigned an empty string ("") or method that extracts two characters from a string starting at the sixth character position (that is, at index five). - [!code-csharp[System.String.Substring#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs#4)] + [!code-csharp-interactive[System.String.Substring#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs#4)] [!code-vb[System.String.Substring#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring4.vb#4)] The following example uses the method in the following three cases to isolate substrings within a string. In two cases the substrings are used in comparisons, and in the third case an exception is thrown because invalid parameters are specified. @@ -12036,12 +12206,12 @@ A string is empty if it is explicitly assigned an empty string ("") or exception. - [!code-csharp[Classic String.Substring1 Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic String.Substring1 Example/CS/source.cs#1)] + [!code-csharp-interactive[Classic String.Substring1 Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic String.Substring1 Example/CS/source.cs#1)] [!code-vb[Classic String.Substring1 Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.Substring1 Example/VB/source.vb#1)] The following example uses the method to separate key/value pairs that are delimited by an equals ("=") character. - [!code-csharp[System.String.Substring#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs#1)] + [!code-csharp-interactive[System.String.Substring#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs#1)] [!code-vb[System.String.Substring#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb#1)] The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. @@ -13844,6 +14014,15 @@ A string is empty if it is explicitly assigned an empty string ("") or Returns a new string in which all leading and trailing occurrences of a set of specified characters from the current object are removed. + + + @@ -13894,10 +14073,9 @@ A string is empty if it is explicitly assigned an empty string ("") or or all the characters in the current instance consist of white-space characters, the method returns . White-space characters are defined by the Unicode standard. The method removes any leading and trailing characters that produce a return value of `true` when they are passed to the method. - - - + ## Examples + The following example uses the method to remove any extra white space from strings entered by the user before concatenating them. [!code-cpp[System.String.Trim#2](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim2.cpp#2)] @@ -14013,10 +14191,11 @@ A string is empty if it is explicitly assigned an empty string ("") or method to remove space, asterisk (*), and apostrophe (') characters from a string. [!code-cpp[System.String.Trim#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim1.cpp#1)] - [!code-csharp[System.String.Trim#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs#1)] + [!code-csharp-interactive[System.String.Trim#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs#1)] [!code-vb[System.String.Trim#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Trim/vb/Trim1.vb#1)] ]]> @@ -14157,7 +14336,7 @@ A string is empty if it is explicitly assigned an empty string ("") or method to trim white space or punctuation marks from the end of a string. - [!code-csharp[System.String.TrimEnd#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.TrimEnd/cs/sample2.cs#2)] + [!code-csharp-interactive[System.String.TrimEnd#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.TrimEnd/cs/sample2.cs#2)] [!code-vb[System.String.TrimEnd#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimEnd/vb/Sample2.vb#2)] ]]> @@ -14298,7 +14477,7 @@ A string is empty if it is explicitly assigned an empty string ("") or method: - [!code-csharp[System.String.TrimStart#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.TrimStart/cs/sample.cs#1)] + [!code-csharp-interactive[System.String.TrimStart#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.TrimStart/cs/sample.cs#1)] [!code-vb[System.String.TrimStart#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb#1)] The following example uses the method to trim white space and comment characters from lines of source code. The `StripComments` method wraps a call to and passes it a character array that contains a space and the comment character, which is an apostrophe ( ' ) in Visual Basic and a slash ( / ) in C#. The method is also called to remove leading white space when evaluating whether a string is a comment. @@ -14323,4 +14502,4 @@ A string is empty if it is explicitly assigned an empty string ("") or - + \ No newline at end of file