C#使用正則表達(dá)式實(shí)現(xiàn)首字母轉(zhuǎn)大寫的方法
本文實(shí)例講述了C#使用正則表達(dá)式實(shí)現(xiàn)首字母轉(zhuǎn)大寫的方法。分享給大家供大家參考,具體如下:
class Program { static void Main(string[] args) { // Input strings. const string s1 = "samuel allen"; const string s2 = "dot net perls"; const string s3 = "Uppercase first letters of all words in the string."; // Write output strings. Console.WriteLine(TextTools.UpperFirst(s1)); Console.WriteLine(TextTools.UpperFirst(s2)); Console.WriteLine(TextTools.UpperFirst(s3)); Console.ReadKey(); } } public static class TextTools { /// <summary> /// Uppercase first letters of all words in the string. /// </summary> public static string UpperFirst(string s) { return Regex.Replace(s, @"\b[a-z]\w+", delegate(Match match) { string v = match.ToString(); return char.ToUpper(v[0]) + v.Substring(1); }); } }
PS:這里再為大家提供2款非常方便的正則表達(dá)式工具供大家參考使用:
JavaScript正則表達(dá)式在線測(cè)試工具:
http://tools.jb51.net/regex/javascript
正則表達(dá)式在線生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
上一篇:C#編程實(shí)現(xiàn)DataTable添加行的方法
欄 目:C#教程
下一篇:Unity3D獲取當(dāng)前鍵盤按鍵及Unity3D鼠標(biāo)、鍵盤的基本操作
本文標(biāo)題:C#使用正則表達(dá)式實(shí)現(xiàn)首字母轉(zhuǎn)大寫的方法
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6851.html
您可能感興趣的文章
- 01-10C#使用Dispose模式實(shí)現(xiàn)手動(dòng)對(duì)資源的釋放
- 01-10C#3.0使用EventLog類寫Windows事件日志的方法
- 01-10C#使用windows服務(wù)開啟應(yīng)用程序的方法
- 01-10c# ArrayList的使用方法小總結(jié)
- 01-10C#使用ADO.Net部件來訪問Access數(shù)據(jù)庫的方法
- 01-10C#使用Mutex簡單實(shí)現(xiàn)程序單實(shí)例運(yùn)行的方法
- 01-10使用Nopcommerce為商城添加滿XX減XX優(yōu)惠券功能
- 01-10C#編程自學(xué)之運(yùn)算符和表達(dá)式
- 01-10C#中yield用法使用說明
- 01-10C#編程和Visual Studio使用技巧(下)


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10delphi制作wav文件的方法
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 04-02jquery與jsp,用jquery