String splitting () function parsing-C #

Source: Internet
Author: User

Today, a friend asked me, if the database field contains data "5, 6, 8, 9", how can I retrieve the values separately, data is extracted first and then Split in CSHARP. However, many friends may not know how to use the Split () function of the string class object function to Split data. Now we will mainly explain this Split. First, make a mark. Later, I will review my own blog posts and learn some knowledge to improve my basic knowledge.

This method of string objects is reloaded five times.

Paste the MS code: This is the Chinese version of VS. COPY it directly.

Code

// Summary:
// Return the System. String Array containing the substring In the instance (separated by elements in the specified System. Char array.
//
// Parameters:
// Separator:
// An array of Unicode characters that separate the substring of this instance, an empty array that does not contain separators, or null.
//// Return result:
// An array whose elements contain substrings in this instance. These substrings are separated by one or more characters in the separator. For more information, see the remarks section.
Public string [] Split (params char [] separator );
//
// Summary:
// Return the System. String Array containing the substring In the instance (separated by elements in the specified System. Char array. The parameter specifies the maximum number of substrings returned.
//
// Parameters:
// Count:
// The maximum number of substrings to return.
//
// Separator:
// An array of Unicode characters that separate the substring of this instance, an empty array that does not contain separators, or null.
//
// Return result:
// An array whose elements contain substrings in this instance. These substrings are separated by one or more characters in the separator. For more information, see the remarks section.
//
// Exception:
// System. ArgumentOutOfRangeException:
// Count is negative.
Public string [] Split (char [] separator, int count );
//
// Summary:
// Return the System. String Array containing the substring in the String (separated by elements in the specified System. Char array. The parameter specifies whether to return an empty array element.
//
// Parameters:
// Options:
// Specify System. StringSplitOptions. RemoveEmptyEntries to omit the null array element in the returned array, or specify System. StringSplitOptions. None
// Contains the empty array elements in the returned array.
//
// Separator:
// An array of Unicode characters that separate the substring of this string, an empty array that does not contain separators, or null.
//
// Return result:
// An array whose elements contain substrings separated by one or more characters. For more information, see the remarks section.
//
// Exception:
// System. ArgumentException:
// Options is not one of the values of System. StringSplitOptions.
[ComVisible (false)]
Public string [] Split (char [] separator, StringSplitOptions options );
//
// Summary:
// Return the System. String Array containing the substring in the String (separated by elements in the specified System. String Array. The parameter specifies whether to return an empty array element.
//
// Parameters:
// Options:
// Specify System. StringSplitOptions. RemoveEmptyEntries to omit the null array element in the returned array, or specify System. StringSplitOptions. None
// Contains the empty array elements in the returned array.
//
// Separator:
// A string array that separates the substring of this string, an empty array that does not contain separators, or null.
//
// Return result:
// An array whose elements contain the substrings in this string. These substrings are separated by one or more strings in the separator. For more information, see the remarks section.
//
// Exception:
// System. ArgumentException:
// Options is not one of the values of System. StringSplitOptions.
[ComVisible (false)]
Public string [] Split (string [] separator, StringSplitOptions options );
//
// Summary:
// Return the System. String Array containing the substring in the String (separated by elements in the specified System. Char array. The parameter specifies the maximum number of substrings to return and whether to return an empty array element.
//
// Parameters:
// Count:
// The maximum number of substrings to return.
//
// Options:
// Specify System. StringSplitOptions. RemoveEmptyEntries to omit the null array element in the returned array, or specify System. StringSplitOptions. None
// Contains the empty array elements in the returned array.
//
// Separator:
// An array of Unicode characters that separate the substring of this string, an empty array that does not contain separators, or null.
//
// Return result:
// An array whose elements contain substrings separated by one or more characters. For more information, see the remarks section.
//
// Exception:
// System. ArgumentException:
// Options is not one of the values of System. StringSplitOptions.
//
// System. ArgumentOutOfRangeException:
// Count is negative.
[ComVisible (false)]
Public string [] Split (char [] separator, int count, StringSplitOptions options );
//
// Summary:
// Return the System. String Array containing the substring in the String (separated by elements in the specified System. String Array. The parameter specifies the maximum number of substrings to return and whether to return an empty array element.
//
// Parameters:
// Count:
// The maximum number of substrings to return.
//
// Options:
// Specify System. StringSplitOptions. RemoveEmptyEntries to omit the null array element in the returned array, or specify System. StringSplitOptions. None
// Contains the empty array elements in the returned array.
//
// Separator:
// A string array that separates the substring of this string, an empty array that does not contain separators, or null.
//
// Return result:
// An array whose elements contain the substrings in this string. These substrings are separated by one or more strings in the separator. For more information, see the remarks section.
//
// Exception:
// System. ArgumentException:
// Options is not one of the values of System. StringSplitOptions.
//
// System. ArgumentOutOfRangeException:
// Count is negative.
[ComVisible (false)]
Public string [] Split (string [] separator, int count, StringSplitOptions options );

----------------------------------------------------------------------------------------------------

Now, I am posting a piece of code to record it. I will not talk about anything else.

Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String a = "5, 6, 9 ";
String [] B;
B = a. Split (',');
For (int I = 0; I <B. Length; I ++)
{
Response. Write (B [I]. ToString () + "</br> ");
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.