asp.net string Common operations (1/2)

Source: Internet
Author: User

string s = String.Empty;
string s = "";
string s = null;

The first 11th is a string variable that points to an empty string, and S does not occupy storage space. s variables can be used, such as S.length
.
The second defines an empty string that points to "" and occupies one byte of storage space, because the escape character represents the end of the string. s variables can be used, such as S.length
The third defines a variable that does not refer to any one storage space, and s cannot be used


String Connection:
--------------------------------------------------------------------------------


protected void Button1_Click (object sender, EventArgs e)
{
String str1= "ABCD", str2= "EFG";
STR1 + = str2;
Response.Write (STR1); Abcdefg
}

--------------------------------------------------------------------------------

To extract characters from a string:
--------------------------------------------------------------------------------

protected void Button1_Click (object sender, EventArgs e)
{
String str = "ABCDEFG";
char C = str[1]; Read Only
Response.Write (c); B
Response.Write (Str[str.length-1]); G
}

--------------------------------------------------------------------------------

To traverse a character from a string:
--------------------------------------------------------------------------------

protected void Button1_Click (object sender, EventArgs e)
{
String str = "ABCDEFG";
for (int i = 0; i < str.length; i++)
{
Response.Write (Str[i] + "<br/>");
}
foreach (char c in str)
{
Response.Write ("}
}

--------------------------------------------------------------------------------

To escape from a character encoding to a character:
--------------------------------------------------------------------------------

protected void Button1_Click (object sender, EventArgs e)
{
String str = "u4e07u4e00";
Response.Write (str); If
}

--------------------------------------------------------------------------------

Home 1 2 last page

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.