¡¾·±ÌåÖÐÎÄ¡¿
¡¾ÉèΪÊ×Ò³¡¿
¡¾¼ÓÈëÊղء¿
µ±Ç°Î»Öãº.Net¼¼ÊõÊ×Ò³ >> Asp.Net¿ª·¢ >> ÀÏÍâ±àµÄ³ÌÐò£¨Èý£©£­£­ÕýÔò±í´ïʽµÄDemo

ÀÏÍâ±àµÄ³ÌÐò£¨Èý£©£­£­ÕýÔò±í´ïʽµÄDemo

2007-07-15 08:00:00  ×÷Õߣº  À´Ô´£º»¥ÁªÍø  ä¯ÀÀ´ÎÊý£º0  ÎÄ×Ö´óС£º¡¾´ó¡¿¡¾ÖС¿¡¾Ð¡¡¿
¼ò½é£ºusing System.Text.RegularExpressions; class Test { 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])) { ...

using System.Text.RegularExpressions;

class Test {

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 + "]");

string result = Regex.Replace(text, @"\w+",

new MatchEvaluator(Test.CapText));

System.Console.WriteLine("result=[" + result + "]");

}

}

ÔðÈα༭£ºadmin
±¾ÎÄÒýÓõØÖ·£º http://www.3pcode.com/net/2007/07/88656.htm
Ïà¹ØÎÄÕÂ