C# 字符串

using System;

namespace ConsoleApp10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string str = "123456789";
Console.WriteLine("{0}", str);
Console.WriteLine("string就是数组一种{0}", str[0]);
char[] cha = str.ToCharArray();
for (int i = 0; i < cha.Length / 2; i++)
{
char temp;
temp = cha[i];
cha[i] = cha[cha.Length - 1 - i];
cha[cha.Length - 1 - i] = temp;
}
str = new string(cha);
Console.WriteLine("{0}", str);
//////////////////////////////////////////
///hell c rust =rust c hell
string str1 = "hell c rust";
Console.WriteLine("数组0:{0}", str1);
string[] str2 = str1.Split(new char[] { ' ', '9' });
string[] str4 = str1.Split(' ', '9', StringSplitOptions.RemoveEmptyEntries);
//string[] str4 = str1.Split(new char[] { ' ', '9' }, StringSplitOptions.RemoveEmptyEntries);
//分隔后遇到的空字符串不作为数组元素的一项返回
//StringSplitOptions.RemoveEmptyEntries
for (int i = 0; i < str2.Length / 2; i++)
{
string temp;
temp = str2[i];
str2[i] = str2[str2.Length - 1 - i];
str2[str2.Length - 1 - i] = temp;

        }
        str1 = string.Join(" ", str2);
        Console.WriteLine("数组1:{0}", str1);
        /////////////////////////////////////////
        ///hudaqun@163.com
        string str5 = "hudaqun@163.com";
        string str6 = str5.Substring(0, 7);
        string str7 = str5.Substring(8, 7);
        Console.WriteLine("{0}", str6);
        Console.WriteLine("{0}", str7);
        int aa = str5.IndexOf("@");
        string str8 = str5.Substring(0, aa);
        Console.WriteLine("{0}", str8);
        int bb = str5.Length;
        string str9 = str5.Substring(aa+1, bb-aa-1);
        Console.WriteLine("{0}", str9);
        Console.ReadKey();

        ////////////////////////////////////////
        ///
        string path = @"C:\Users\SpringRain\Desktop\1.txt";
        string contents =File.ReadAllLines(path, .Default);





    }
}

}

posted @ 2022-10-25 10:04  淼淼淼26  阅读(18)  评论(0)    收藏  举报