String and string, Stringstring

Source: Internet
Author: User

String and string, Stringstring

StringAndStringDifference

From the perspective of location:

 1.String is the String in. NET Framework, and the string in lower case is the string in C # language.

2. If you delete using System;, there is no upper-case String. System is a function name in the. NET Framework class library.

In terms of nature:

1.String is a keyword and String is a class. string cannot be the name of a class, structure, enumeration, field, variable, method, or attribute.

2.When writing code in C #, try to use a lower-case string, which is more compliant. If efficiency is pursued, you can use a String in upper case, because after compilation, lowercase strings are converted to uppercase strings, which can reduce the compilation load and improve the running efficiency.

3.String represents a string of Unicode characters. String is the alias of a string in. NET Framework. It is more intuitive to test the equality of strings.

StringDetails:

String s = string. Empty: A string variable pointing to an Empty string. The. s variable can be used, for example, s. Length.
String s = ""; an empty string pointing to "\ 0" occupies a byte storage space, because the Escape Character \ 0 indicates that the string ends. s variable can be used, such as s. Length
String s = null; a variable that does not belong to any bucket. s cannot be used.
           

Single Character Segmentation:

String s = "abcdeabcdeabcde ";

String [] sArray = s. Split ('C ');

Foreach (string I in sArray)

Console. WriteLine (I. ToString ());

Output the following results:

AB

Deab

Deab

De

Separate multiple characters:

String s = "abcdeabcdeabcde

String [] sArray1 = s. Split (new char [3] {'C', 'D', 'E '});

Foreach (string I in sArray1)

Console. WriteLine (I. ToString ());

You can output the following results:

AB

AB

AB

Separate multiple characters(Regular Expression):

String content = "agcsmallmacsmallgggsmallytx ";

String [] resultString = Regex. Split (content, "small", RegexOptions. IgnoreCase)

Foreach (string I in resultString)

Console. WriteLine (I. ToString ());

Output the following result: agc

Mac

Ggg

Ytx

Related Article

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.