📄 class1.cs
字号:
using System;
namespace TestStrings
{
public class TestStringsApp
{
public static void Main(string[] args)
{
string a = "strong";
// replace all 'o' with 'i'
string b = a.Replace('o', 'i');
Console.WriteLine(b);
string c = b.Insert(3, "engthen");
string d = c.ToUpper();
Console.WriteLine(d);
if (d == c) // different
{
Console.WriteLine("same");
}
else
{
Console.WriteLine("different");
}
string q = "Foo";
q = q.Replace('o', 'i');
Console.WriteLine(q);
string e = "dog" + "bee";
e += "cat";
string f = e.Substring(1,7);
Console.WriteLine(f);
for (int i = 0; i < f.Length; i++)
{
Console.Write("{0,-3}", f[i]);
}
Console.WriteLine();
string g = null;
if (f.StartsWith("og"))
{
g = f.Remove(2,3);
}
Console.WriteLine(g);
int x = 16;
decimal y = 3.57m;
string h = String.Format(
"item {0} sells at {1:C}", x, y);
Console.WriteLine(h);
string t =
"item " + 12 + " sells at " + '\xA3' + 3.45;
Console.WriteLine(t);
Console.WriteLine();
// this works because last param is a params object[]
Console.WriteLine(
"Hello {0} {1} {2} {3} {4} {5} {6} {7} {8}",
123, 45.67, true, 'Q', 4, 5, 6, 7, '8');
// this also works as from RC1
string u = String.Format(
"Hello {0} {1} {2} {3} {4} {5} {6} {7} {8}",
123, 45.67, true, 'Q', 4, 5, 6, 7, '8');
Console.WriteLine(u);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -