String s = string. empty;
String s = "";
String s = null;
The first 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 type defines an empty string pointing to "", occupying a byte storage space, because the Escape Character represents the end of the string. s variable, such as s. length.
The third type defines a variable that is not directed to any bucket, and s cannot be used.
String connection:
--------------------------------------------------------------------------------
Protected void button#click (object sender, eventargs e)
{
String str1 = "abcd", str2 = "efg ";
Str1 + = str2;
Response. write (str1); // abcdefg
}
--------------------------------------------------------------------------------
Extract characters from a string:
--------------------------------------------------------------------------------
Protected void button#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
}
--------------------------------------------------------------------------------
Traverse characters from strings:
--------------------------------------------------------------------------------
Protected void button#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 ("}
}
--------------------------------------------------------------------------------
Escape from character encoding to character:
--------------------------------------------------------------------------------
Protected void button#click (object sender, eventargs e)
{
String str = "u4e07u4e00 ";
Response. write (str); // In case
}
--------------------------------------------------------------------------------
1 2