using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace learn_str_int
{
internal class Program
{
static void Main(string[] args)
{
// 数字的几种方法2
int argInt = 123;
// 转换成string
Console.WriteLine($"{argInt.ToString()}");
// 和123比较
Console.WriteLine($"{argInt.CompareTo(123)}");
// 是否等于123
Console.WriteLine($"{argInt.Equals(123)}");
// 获取变量类型
Console.WriteLine($"{argInt.GetType()}");
// 字符串的几种方法
string aaa = " _Yes_ ";
// 获取字符串长度
Console.WriteLine($"{aaa.Length}");
// 判断字符串是否包含子字符串
Console.WriteLine($"{aaa.Contains("s_")}");
// 返回字符串中的最小值
Console.WriteLine($"{aaa.Min()}");
// 字符串全转换成小写
Console.WriteLine($"{aaa.ToLower()}");
// 字符串转换成char组成的列表
Console.WriteLine($"{aaa.ToArray()}");
// 获取最大的字符
Console.WriteLine($"{aaa.Max()}");
// 字符串是否以xx结尾
Console.WriteLine($"{aaa.EndsWith("_ ")}");
// 字符串是否以xx开头
Console.WriteLine($"{aaa.StartsWith(" _")}");
// 字符串是否与另一个字符串相等
Console.WriteLine($"{aaa.Equals(" _Yes_ ")}");
// 在字符串的指定位置插入子字符串
Console.WriteLine($"{aaa.Insert(2, "aaa")}");
// 移除字符串指定位置之间的字符
Console.WriteLine($"{aaa.Remove(1, 3)}");
// 替换字符串中的指定内容
Console.WriteLine($"{aaa.Replace("es", "cccc")}");
// 字符串左边填充到指定长度,默认以空格填充
Console.WriteLine($"{aaa.PadLeft(10)}");
// 字符串右边填充到指定长度,以指定的字符串填充
Console.WriteLine($"{aaa.PadRight(10, '*')}");
// 字符串以指定的字符分割
Console.WriteLine($"{aaa.Split('e')}");
// 字符串两边移除指定的字符
Console.WriteLine($"{aaa.Trim(' ')}");
// 字符串左边移除指定的字符
Console.WriteLine($"{aaa.TrimStart(' ')}");
// 字符串右边移除指定的字符
Console.WriteLine($"{aaa.TrimEnd(' ')}");
// 字符串都转换成大写
Console.WriteLine($"{aaa.ToUpper()}");
// 字符串都转换成小写
Console.WriteLine($"{aaa.ToLower()}");
// 字符串转化为字符列表
Console.WriteLine($"{aaa.ToCharArray()}");
Console.ReadKey();
}
}
}
结果输出:
123
0
True
System.Int32
7
True
_yes_
System.Char[]
s
True
True
True
_aaaYes_
s_
_Ycccc_
_Yes_
_Yes_ ***
System.String[]
_Yes_
_Yes_
_Yes_
_YES_
_yes_
System.Char[]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)