C # Foundation (String)

Source: Internet
Author: User

Https://msdn.microsoft.com/zh-cn/library/84787k22 (v=vs.110). aspx

1, Compare
Basic methods
public static int Compare (string stra,string StrB)
Call
String.Compare (S1, S2)
Overload 1

public static int Compare (
String stra,string strb,bool ignoreCase  //Ignore case)
Overload 2
public static int Compare (string stra,string strb,bool ignorecase,cultureinfo culture  //An object that provides culture-specific comparison information)

2, CompareTo

Https://www.cnblogs.com/jhxk/articles/1733811.html

String.CompareTo syntax

public int CompareTo (
String StrB
CompareTo is seldom used, do not use CompareTo to compare two strings for equality, use Equals. 3. Equals
52446664

public bool Equals (string value);
public static bool Equals (string a,string b);

4. Formatting strings
public static string Format (string Format,object obj);
invocation Example
String. Format ("{0},{1}", STRA,STRB)
String. Format ("{0}:d", stra)//formatted date

5. Intercepting strings
public string substring (int startindex,int length);

6. Split string
Public string[] Split (param char[] separator);
7. Inserting and populating strings
public string Insert (int startindex,string value);
8. Padding string

Method 1:

Use String. PadRight ()

Method 2:

To customize a static method for a string to be padded:

public static string PadRight (string src, char C, Int32 totallength)
{
if (Totallength < src. Length)
return SRC;
return src + new String (c, totallength-src. Length);
}

Https://www.cnblogs.com/IamJiangXiaoKun/p/5737822.html

9. Delete a string

Str1. Remove (3); String str1 deleted from third bit

Str1.  Remove (3,10); String str1 from the third bit, delete the number of bits 10 bits

10. Copying strings

Copy ()

Strb=string. Copy (stra)//copying character stra to STRB

11. Replace string

String Strb=stra.replace ("One", "one"); Replace one in string stra with one







C # Foundation (String)

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.