day 10 C#打卡
1.String类的使用(1)
using System;
namespace ConsoleApp10
{
class program
{
static void Main(string[] args)
{
string str = new string('B', 20);
Console.WriteLine(str);
string str1 = new string(new char[] { 'H', 'e', 'l', 'l', 'o' });
Console.WriteLine(str1);
string[] str2 = new string[] { "nihaoya","我好呀" };
Console.WriteLine("数组的元素有{0}个", str2.Length);
string[] str3 = new string[] { "1","2","3","4","5" };
Console.WriteLine("有{0}个字符", str3.Length);
string Company = "12345678";
for(int i = 0; i < 8; i++)
{
char employee = Company[i];
Console.WriteLine("employee的编号为{0}", employee);
}
string str4 = "china";
Console.WriteLine("{1}转换为大写字母为{0}", str4.ToUpper(),str4);
string str5 = "AMErican";
Console.WriteLine("{0}转换为小写字母为{1}", str5, str5.ToLower());
string str6 = "Welcome to NewYork!";
string str7 = "welcome to Beijing!";
if (string.Compare(str6, str7) == 1)
Console.WriteLine("str6在字典中的位置大于str7");
else if (string.Compare(str6, str7) == -1)
Console.WriteLine("str6在字典中的位置小于str7");
else if (string.Compare(str6, str7) == 0)
Console.WriteLine("str6与str7的位置相同");
string str8 = "baby";
string str9 = "BABY";
if (string.Compare(str8, str9, false) == 0)
Console.WriteLine("不忽略大小写,str8与str9的位置相同");
else
Console.WriteLine("不忽略大小写,str8与str9的位置不相同");
Console.ReadLine();
}
}
}
运行结果如下
|