. NET What do you know about the strings?

Source: Internet
Author: User
Tags uppercase character

Characteristics of strings
1. immutability Because the string is immutable, each time the string is modified, a separate copy of the string is created (a copy of the string is copied).       The change is only because it points to a new address.              ps:vs2005 Instant Window & variable, take address:  VS2010 above even the window * variable, only takes the heap address. 2. String pool (for string constants only) when there are multiple identical string constants in a program, multiple variables point to the same piece of string in memory! This feature is called a string pool. The reason the string does not cause confusion in the program is because of the immutability of the string.
Member methods and properties of string

PS: There are many overloaded ways, not listed.

1.Contains (String str) determines whether the string is contained, specifying a string.

Usage

String str = "HelloWorld";

Str.   Contains ("Hello"); True

2.StartsWith (String str)

Determines whether the string object begins with a specified string.

3.EndWith (String str)

Determines whether the string object ends with a specified string.

4.Length Properties

Gets the length of the string

5.IndexOf (String str)

Gets the specified character/string ... The position of the first occurrence in the object string.

6.LastIndexOf (String str)

Gets the specified character/string .... The position that appears last in the object string.

7.SubString (int start)

SubString (int strat, int length) intercepts the string from the specified position.

8.ToLower ()

Converts the string to lowercase, returning a new all-lowercase character.

9.ToUpper ()

Converts the string to uppercase, returning a new all-uppercase character.

Replace (String oldstr,string newstr)

Replaces the old string part of the object string with a new string.

11.Trim () remove spaces at both ends of the object string

TrimStart () Remove space at the beginning of the object string

TrimEnd () Remove space at the end of the object string

PS: Other overloads of Trim () can be used if you want to strip other characters of other characters at the end of the opening.

12.Split () splits the object string into an array of strings, according to the specified characters!

The overloads of Split () are also many,

For example, Split (new char[]{' | '}, stringsplitoption.removeemptyentries)//Delete empty data

static method of String

1.IsNullOrEmpty (String)

String. IsNullOrEmpty (STR1) determines whether a string is null, or is an empty string.

2.Equals (String,string,stringcomparison.ordianlignore) ignores case comparison of two strings. 3.Join (string,string[]) stitch an array into a string by the specified string.

. NET What do you know about the strings?

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.