static void Main(string[] args)
{
Console.WriteLine("请输入一个字符串");
string str = Console.ReadLine();
str = Reverse(str);
Console.WriteLine(str);
Console.Read();
}
public static string Reverse(string input)
{
char[] chs = input.ToCharArray();
for(int i=0;i
{
char ch;
ch = chs[i];
chs[i] = chs[chs.Length - i - 1];
chs[chs.Length - i - 1] = ch;
}
return new string(chs);
}
static void Main(string[] args)
{
Console.WriteLine("请输入一句话:");
string[] strs = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for(int i =0;i
{
strs[i] = Reverse(strs[i]);
}
Console.WriteLine(string.Join(" ", strs));
Console.Read();
}
public static string Reverse(string input)
{
char[] chs = input.ToCharArray();
for(int i=0;i
{
char ch;
ch = chs[i];
chs[i] = chs[chs.Length - i - 1];
chs[chs.Length - i - 1] = ch;
}
return new string(chs);
}
方法1:
static void Main(string[] args)
{
string str = DateTime.Now.ToLongDateString();
// string[] strs = str.Split('年', '月', '日');
string[] strs = str.Split("年月日".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
for(int i =0;i
{
Console.Write(strs[i]+" ");
}
Console.Read();
}
方法2:
static void Main(string[] args)
{
string str = DateTime.Now.ToLongDateString();
int iYear, iMonth, iDay;
iYear = str.IndexOf('年');
iMonth = str.IndexOf('月');
iDay = str.IndexOf('日');
string str1 = str.Substring(0, iYear);
string str2 = str.Substring(iYear+1, iMonth - iYear-1);
string str3 = str.Substring(iMonth+1, iDay - iMonth-1);
Console.WriteLine("{0} {1} {2}", str1, str2, str3);
Console.Read();
}