随笔 - 63,  文章 - 0,  评论 - 4,  阅读 - 10万
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[]
posted on   盈盈的月儿  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示