c#编程:接收键盘输入的英文字符串(单词之间用空格隔开),将字符串中出现的单词首字母改成大写后输出
.输入一个字符串,单词间用空格分隔,自定义按照Camel命名规则转换输出;示例:请输入一个字符串,各单词以空格隔开Myfavoritesport按Camel规则转换后名称...
.输入一个字符串,单词间用空格分隔,自定义按照Camel命名规则转换输出;示例:请输入一个字符串,各单词以空格隔开My favorite sport按Camel规则转换后名称是: myFavoriteSport提示:先进行分隔,再将后两个单词的首字母转成大写,再进行组合连接。
展开
1个回答
展开全部
private string convertInput(string inPutString)
{
List<string> wordList = new List<string>();
string[] wordArray = inPutString.Split();
for (int i = 0; i < wordArray.Length; i++)
{
char[] characters = wordArray[i].ToCharArray();
string tmpWord = string.Empty;
for (int j = 0; j < characters.Length; j++)
{
if (j == 0)
{
tmpWord = characters[j].ToString().ToUpper();
}
else
{
tmpWord+=characters[j].ToString();
}
}
wordList.Add(tmpWord);
}
string resultString = string.Empty;
foreach (string tmpString in wordList)
{
resultString += tmpString;
}
return resultString;
}
{
List<string> wordList = new List<string>();
string[] wordArray = inPutString.Split();
for (int i = 0; i < wordArray.Length; i++)
{
char[] characters = wordArray[i].ToCharArray();
string tmpWord = string.Empty;
for (int j = 0; j < characters.Length; j++)
{
if (j == 0)
{
tmpWord = characters[j].ToString().ToUpper();
}
else
{
tmpWord+=characters[j].ToString();
}
}
wordList.Add(tmpWord);
}
string resultString = string.Empty;
foreach (string tmpString in wordList)
{
resultString += tmpString;
}
return resultString;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询