匹配所有单词首字母大写
2009-02-12 16:18
316 查看
using System;
using System.Text.RegularExpressions;
class RegExSample
{
static string CapText(Match m)
{
// Get the matched string.
string x = m.ToString();
// If the first char is lower case...
if (char.IsLower(x[0])) { // Capitalize it.
return char.ToUpper(x[0]) + x.Substring(1, x.Length - 1);
}
return x;
}
static void Main()
{
string text = "four score and seven years ago";
System.Console.WriteLine("text=[" + text + "]");
Regex rx = new Regex(@"\w+");
string result = rx.Replace(text, new MatchEvaluator(RegExSample.CapText));
System.Console.WriteLine("result=[" + result + "]");
}
}
using System.Text.RegularExpressions;
class RegExSample
{
static string CapText(Match m)
{
// Get the matched string.
string x = m.ToString();
// If the first char is lower case...
if (char.IsLower(x[0])) { // Capitalize it.
return char.ToUpper(x[0]) + x.Substring(1, x.Length - 1);
}
return x;
}
static void Main()
{
string text = "four score and seven years ago";
System.Console.WriteLine("text=[" + text + "]");
Regex rx = new Regex(@"\w+");
string result = rx.Replace(text, new MatchEvaluator(RegExSample.CapText));
System.Console.WriteLine("result=[" + result + "]");
}
}
相关文章推荐
- 大写句子中所有单词首字母
- 词组缩写 英语句子所有单词首字母大写输出 C语言/C++编程题
- 将所有单词首字母替换成大写
- string.capwords()--将字符串中所有单词的首字母大写
- C# 所有单词首字母改为大写的方法
- 通过PHP把一篇英文文档中所有单词的首字母转为大写
- [Go] 第一个单词首字母变大写:Ucfirst(),第一个单词首字母变小写:Lcfirst()
- C 单词首字母大写&统计单词个数
- 查出某一个字段的单词的首字母为大写的值
- 使用简单的nltk的API 得到一系列字母可以组成的所有单词
- Android EditText输入使每一个单词首字母大写
- 给出一个2D板和字典中的单词列表,找到棋盘上的所有单词。每个单词必须由顺序相邻单元格的字母构成。不能重复使用
- SQLServer设置单词首字母大写
- 67.读入字符串把每个单词开始的字母大写
- 单词首字母大写
- 每个单词间一个空格,首字母大写
- 如何让输入的单词首字母大写
- 将ss所指字符串中所有下标为奇数位置上的字母转换为大写
- 将单词首字母大写的JS脚本工具
- 定义常量的时候,所有字母都要大写