2016-11-21 (1) (C # related)---text

Source: Internet
Author: User

------------------------StringBuilder----------------------------

string represents a constant string, so the StringBuilder performs a dynamic operation on the string

If the increase in the length of the string exceeds the range, a larger space is allocated and the original content is copied over. The original space will be recycled.

I'm not reading it. Is it possible to maintain multiple fields of type string? If you do not do this, you may have been overwritten when the reference object is used externally.

Field inside: Maximum Capacity (Int32.MaxValue) capacity length character array

StringBuilder there are two kinds of times when you need to allocate a new object 1> exceeds the length of the string 2> when you call ToString, you change the character array

If you want to use threads, you need to be aware of thread safety

ensurecapacity () specifies the size of the capacity if the capacity of the string is less than the specified value, the assignment is not changed to the specified value.

chars allows us to access arrays in an array-like way.

Appendinsert   (); Specify insert

AppendFormat  (); Converts the specified object format into a string and then adds it to the StringBuilder.

Replace   (); Converts a string or character specified inside a string into a parameter.

Remove   () ; Delete the contents of a specified range

Equals    (); Judgment is not equal.

string and StringBuilder methods are not equivalent, so it may be necessary to switch back and forth when doing string manipulation

--------------------gets the string representation of the object-------------------------------

System.Object inside defines a common parameterless tostring any object can call this function to get the corresponding string

But the default is to return the type name if it takes a meaningful tosring so long to rewrite.

This passage was left to be used back to see.

The notes after this are all lite.

------------------------------------------------------------------------------------Lite Version---------------------------------- --------------------------------------------------

------------------------------------------Formatting------------------------------------------------------

Different Types Formatting format Parameters with IFormattable ToString first parameter

The string is synthesized with {1} instead of parameters.

Example: String.Format ("{1},{2}{3}", Value,num,object); The following three formats are not the same.

This function invokes the ToString function of the argument itself.

Custom Formatter

AppendFormat ()

Parse () parses a string into another type of object

Example: Int32 num1= int32.parse ("123", numberstyles.allowleadingwhite,null); The second argument is to ignore spaces

The prase parsing of datetime is not good for accurate parsing with praseexact ();

-----------------------------------------conversion between characters and bytes (296 pages)--------------------------------------

Multi-byte Smaller Unicode larger conversion saves space

UTF8 encoded UTF16 encoding

Example: String balue = "AAAAA";

Encoding encodingU8 = System.Text.Encoding.UTF8; Encode with UTF8 mode

byte[] Strbuff = encodingu8.getbytes (Balue);

I used to check it on the internet before. Re-use the re-look

Encoding and decoding of--------------------------------------byte characters-------------------------------------------------

Decoding the data stream

Encoding.getdecoder (); The returned decoder class object can be saved with the remaining remaining data and then the next piece of data continues to be used

Encoidng.getencoder (); Returns a encoder class object used to encode a block of data

2016-11-21 (1) (C # related)---text

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.