首页 > 编程语言 >c# 字符串2

c# 字符串2

时间:2022-10-26 00:11:06浏览次数:41  
标签:abc Console string c# str1 a1 WriteLine 字符串

namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");

        string path = @"C:\c#\1.txt";
        string[] contents = File.ReadAllLines(path, System.Text.Encoding.Default);
        //string[] contents = File.ReadAllLines(path, System.Text.Encoding.UTF8);
        for (int i = 0; i < contents.Length; i++)
        {
            string[] str1 = contents[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Console.WriteLine("{0}|{1}", str1[0].Length > 5 ? str1[0].Substring(0, 5) + "......" : str1[0], str1[1]);
        }
        ////////////////////////////////////////////////////////////////////////////
        ///abcdefdgefffeffffaaaedd
        string str11 = "abcdefdgefffeffffaaaedd";
        int abc = str11.IndexOf("e",0);
        Console.WriteLine("{0}", abc);
        
        while (abc!=-1)
        {
            abc = str11.IndexOf("e", abc+1);
            if (abc==-1)
            {
                break;
            }
            Console.WriteLine("{0}", abc);
        }
        Console.ReadKey();
        //////////////////////////////////////////////////
        ///"老牛非常邪恶"
        string a1 = "老牛非常邪恶";
        Console.WriteLine("{0}", a1);
        if (a1.Contains("邪恶"))
        {
           a1= a1.Replace("邪恶", "**");
        }
        Console.WriteLine("{0}", a1);

        /////////////////////////////////////////////////
        ///"Q","wW","eee","rrrrrr"
        ///Q|wW|eee|rrrrrr
        string[] a22 = { "Q", "wW", "eee", "rrrrrr" };
        string a33 = string.Join("|", a22);
        Console.WriteLine("{0}", a33);
        string[] a44 = a33.Split("|",StringSplitOptions.RemoveEmptyEntries);
        Console.ReadKey();
        //////////////////////////////
        ///






    }
}

}

标签:abc,Console,string,c#,str1,a1,WriteLine,字符串
From: https://www.cnblogs.com/hudaqun/p/16826903.html

相关文章