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
}
--------------------------------------------------------------------------------