字符串
string类
.Length获取长度
字符串相加链接起来
CompareTo方法返回的是0和1,-1,三种返回代表三种情况
Replace("","")将字符串里左边指定字符替换成右边指定字符(可以单个字符的切换,也可以字符串替换,但不能交叉替换)
Substring(,)第一个参数是从哪里开始,第二个参数是读取多少个字符
IndexOf()参数是字符串,IndexOfAny是单个字符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace learn
{
class A
{
static void Main(string[] args)
{
string web = "touming.xyz";
Console.WriteLine("域名:" + web);
Console.WriteLine("域名长度:" + web.Length);
web = "www." + web;//+=情况下,添加内容默认在被添加内容的后面
Console.WriteLine("完整域名:" + web);
foreach (char ret in web)
{
Console.Write(ret + " ");
}
Console.WriteLine("");
string into = "www.touming.xz";
Console.WriteLine("比较:" + into);
int res = web.CompareTo(into);
Console.WriteLine("返回值:" + res);
web = web.Replace(".", "_");
Console.WriteLine(web);
web = web.Replace("_", ".");
Console.WriteLine(web);
Console.WriteLine(web.Substring(4, 7));
int n = web.IndexOf("x");
Console.WriteLine(n);
}
}
}
StringBuilder类
StringBuilder就是一个类,创建一个StringBuilder需要构造一个对象。
StringBuilder stringBuilder = new StringBuilder("www.touming.xyz");
StringBuilder的构造函数传参有两种,一种是字符串,将字符传递给构造函数并赋予对象
第二种是整数,表示创建一个n个字符的空间,但暂时不放字符进去。
结合为
StringBuilder num = new StringBuilder("www.touming.xyz",30);
和