【发布时间】:2015-07-14 05:02:04
【问题描述】:
我必须将用户输入的每个单词的首字母转换为大写。我不认为我做对了,所以它不起作用,但我不确定哪里出了问题 D:提前谢谢你的帮助! ^^
static void Main(string[] args)
{
Console.Write("Enter anything: ");
string x = Console.ReadLine();
string pattern = "^";
Regex expression = new Regex(pattern);
var regexp = new System.Text.RegularExpressions.Regex(pattern);
Match result = expression.Match(x);
Console.WriteLine(x);
foreach(var match in x)
{
Console.Write(match);
}
Console.WriteLine();
}
【问题讨论】:
-
你能添加一些输入和预期输出吗?
-
你有义务使用
Regex吗? -
@sybren 是的!我必须使用正则表达式 D:
-
@vks 例如,如果我输入“hello i am sam”,它应该打印为“Hello I Am Sam”
-
@eyeballs 这是一个使用
Regex的示例:tutorialspoint.com/javaexamples/regular_case.htm