using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class User
{
public void showName()
{
Console.WriteLine("请输入你的姓名:");
string strUserName = Console.ReadLine();
Console.WriteLine("格式化处理后你的姓名:");
string name = FormateName(strUserName);
Console.WriteLine(name);
}
public string FormateName(string strUserName)
{
string[] strNameItem = strUserName.Split(new char[] { ' ' });
for (int i = 0; i <strNameItem.Length; i++)
{
strNameItem[i] = strNameItem[i].Substring(0, 1).ToUpper() + strNameItem[i].Substring(1).ToLower();
}
return String.Join("", strNameItem);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
User user = new User();
user.showName();
Console.ReadLine();
}
}
}
c#第四章深入String类上机题2
最新推荐文章于 2020-02-20 20:10:17 发布