是的 ,我是做一到作业,从控制台输入一段字符啊 ,先除去空格,在将首字母大写其他字母小写 如 my name is chen jun MyNameIsChenJun
//作业要自己来啊,读书最起码作业要会写 string str = "my name is chen jun"; string[] arr = str.Split(' '); string resultStr = string.Empty; for (int i = 0; i < arr.Length; i++) { resultStr += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(arr[i]); }
resultStr 就是你要的结果。。结果为:MyNameIsChenJun
刚开始学! 你的这段代码我还没有接触过 遇到问题了 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace jieduan4 { class Program { static void Main(string[] args) { string answer; string zifu;//用户输入字符串
do { Console.WriteLine("请输入一个字符串,各单词以空格分隔:"); zifu =Console.ReadLine(); pascalzifu (ref zifu);
你是说的命名规范?对首字母和后面单词的首字母大写。。类或结构、接口、枚举名、枚举值、事件、自定义异常、公共字段、方法、命名空间、属性等用 Pascal命名
如 my name is chen jun
MyNameIsChenJun
string str = "my name is chen jun";
string[] arr = str.Split(' ');
string resultStr = string.Empty;
for (int i = 0; i < arr.Length; i++)
{
resultStr += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(arr[i]);
}
resultStr 就是你要的结果。。结果为:MyNameIsChenJun
遇到问题了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace jieduan4
{
class Program
{
static void Main(string[] args)
{
string answer;
string zifu;//用户输入字符串
do
{
Console.WriteLine("请输入一个字符串,各单词以空格分隔:");
zifu =Console.ReadLine();
pascalzifu (ref zifu);
Console.WriteLine("按Pascal规则转换后的名称是:{0}",zifu );
Console.WriteLine ("还要继续吗?(y/n)");
answer =Console.ReadLine();
}while(answer=="y");
}
private static void pascalzifu(ref string zifu)
{ string[] words;//存储单词数组
string temp;//临时存储变量
string tempword;
words = zifu.Split(' ');
//处理单词 temp=zifu; for (int i = 0; i < words.Length; i++)
{
//将首字母变成大写
tempword = words[i].Substring(0, 1).ToUpper();
temp += tempword; tempword = words[i].Substring(1).ToLower();
temp+= tempword;
}
zifu = temp;
}
}
}
不过这段代码还不太明白
resultStr += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(arr[i]);
我输入 my name is chen jun
输出的是my name is chen junMyNameIsChenJun
要求要实现的是MyNameIsChenJun