小東西

大量字串串接

String str = null();

System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i = 0;i<=100;i++)
{
    sb.Append(i.ToString() + "<br>");
}

Response.write(sb.ToString());

String 常用方法

C#的foreach

String str = "abcde";
str.length //5
str.Replace("ab","ba"); //bacde
str.Contains("cd"); //true
str.IndexOf("d"); //3
str.IndexOf("g"); //-1
str = "Hello world, I love C#.";
String[] arr = str.Spilt(' ');

foreach(String s in arr)
{
    Response.write("<br>" + s);    
}
//
Hello
world,
I
love
C#.

Last updated