. Net C # string learning Summary

Source: Internet
Author: User

In the past, I used to forward others' posts. Today I am sending my study notes:
(1) compare strings
Compareto:
Str1.compareto (str2); returns int
If str1 is longer than str2, return 1. If str2 is longer than str1, return-1.
If the values are equal, 0 is returned.
Equals:
Str1.equals (str2); Return bool
Returns true if str1 is equal to str2; otherwise, returns false.
(2) Positioning characters
Int I = str1.indexof (str2 );
Find the character or substring str2 in str1 and return the index count starting from "0 ".
(3) format the string
Format: format any numeric enumeration date as a string of a specific format
Syntax: public static string format (string format, object ARGO );
The first parameter is: format. The second parameter is the object to be formatted.
I understand it as a user-defined format for data processing.
(4) Intercepting substrings
Substring:
Syntax: Public string substring (INT first, int length );
The index intercepts the length of the substring from first.
(5) separator string
Split:
Syntax: Public String [] Split (char [] SEP );
Splits a string into a string group by using parameters as the separator.
For example:
Str1 = '1 | 2 | 3 | 4 | 5 ";
String [] idnum = str1.split ('| ');
(6) Insert a string
Syntax: Public String insert (INT index, string value );
Here, index is the index location to be inserted, and value is the substring to be inserted.
(7) Fill in the string
Syntax: Public String padleft (INT total, char padchar );
It indicates filling the character padchar on the left side of the string to make the total length after filling into total. Note: it is the length after filling.
Similarly, you can also fill in the right, padright
(8) delete strings and substrings
Syntax: Public String remove (INT index, int count );
Str1.remove (5, 9 );
From str1, from index 5, 9 characters after deletion. In syntax, index is the index of the characters to be deleted, and count is the number of characters to be deleted.
(9) Remove a string
Syntax: Public String trimstart (char [] trimchars );
Str1.trimstart ('% ','#');
That is, from the 0 index position of str1, the characters % and # are deleted backward. If the next character is not % and #, it is stopped.
(10) copy a string
Needless to say, Public String Copy (string to be copied );
(11) Replacing strings
Syntax: Public String Replace (string old, string new );
In the parameter, old is the substring to be replaced, and new is the substring to be replaced.

I hope it will be helpful and helpful to everyone.

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.