What do you know about strings in. NET ?,. NET string

Source: Internet
Author: User

What do you know about strings in. NET ?,. NET string
Character string features

1. ImmutableBecause the string is unchangeable, each time you modify the string, you create a separate string copy (copy a string copy ). The only difference is that it points to a new address. Ps: vs2005 instant window & variable, get the address .. If the window * variable is above vs2010, only the heap address is used.2. String pool (for string constants only)When a program has multiple identical string constants, multiple variables point to the same string in memory! This feature is called a string pool. The reason why the string does not cause program confusion is that the string is non-mutable.
Member methods and attributes of String

PS: There are many reload methods, which are not listed one by one.

1. Contains (String str)Determines whether a string contains the specified string.

Usage

String str = "helloworld ";

Str. Contains ("hello"); // true

2. StartsWith (String str)

Determines whether the string object starts with a specified string.

3. EndWith (String str)

Determines whether the string object ends with a specified string.

4. Length attribute

Returns the length of a string.

5. IndexOf (String str) 

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

6. LastIndexOf (String str)

Obtains the position of the last occurrence of the specified character/string... in the object string.

7. SubString (int start)

SubString (int strat, int length)Truncates a string from a specified position.

8. ToLower ()

Converts a string to lowercase and returns a new string in full lowercase.

9. ToUpper ()

Converts a string to uppercase and returns a new string in uppercase.

10. Replace (string oldStr, string newStr)

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

11. Trim ()Removes spaces at both ends of an object string.

TrimStart () removes spaces starting with an object string

TrimEnd () removes spaces at the end of the object string

PS: If you want to remove other starting and ending characters and other characters, you can use other overload of Trim.

12. Split ()Splits an object string into a String Array Based on specified characters!

Split () has the same heavy load,

For example, Split (new char [] {'|'}, StringSplitOption. RemoveEmptyEntries) // Delete NULL data

Static String method

1. IsNullOrEmpty (string)

// String. IsNullOrEmpty (str1) determines whether a string is null or a null string.

2. Equals (string, string, StringComparison. OrdianlIgnore)Ignore case sensitivity to compare whether the two strings are the same.3. Join (string, string [])Concatenates an array into a string based on the specified string.

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: [email protected] 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.