C # Summary string

Source: Internet
Author: User

C # also learned for a long time, although still ignorant, but still have a harvest, and then summed up
ToCharArray string array

String text= "haha, Xiao Yang teacher is young again"
char[] chs=text. ToCharArray ();
Chs[5]= "very";//modifier
string str =new string (CHS);
Console.WriteLine (str);

Converts a string to lowercase

Str2=str2. ToLower ();


Converts a string to uppercase

Str1=str1. Upper ();


Ignore case comparison

Str1.equals (str2,string comparison.ordinalignorecase);


Some characters or strings in a string are replaced

Name=name. Repalce (' very ', ' no ') '


Find a string index and intercept

Str=str. Substring (3,6);//Intercept string


To determine whether a substring is contained in a string
(If "evil" is included in the string, replace evil with purity.)

BOOL Result=name.contains ("evil");
if (result)
{
name=name. Replace ("Evil", "* *");
Console.WriteLine (name);
else
{
Console.WriteLine (name);
}


Determines whether a string starts with a string
StartsWith

String str= "Xiao Yang is very pure";
BOOL Result=str. Startwith ("Xiao Yang");
if (result)
{
Console.WriteLine ("Has this string")
}
else
{
Console.WriteLine ("No This string")
}


Determines whether a string ends with a string
EndsWith

String str= "Xiao Yang is very pure";
BOOL Result=str. EndsWith ("purity");
if (result)
{
Console.WriteLine ("Has this string")
}
else
{
Console.WriteLine ("No This string")
}


The general feeling to sum up a lot, but still a little bit, become the basic knowledge of the repeated.

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.