c#中怎么将字符串中每个词的第一个字母转换成大写 c#中怎么将字符串中每个词的第一个字母转换成大写,其他的转换成小写比如将 HELLO,good,HoW 转换成 Hello,Good,How 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 "good".ToUpper();这样就可以转换了... 转小写: "HELLO".ToLower();再用一个循环判断不是可以了吗 string test = "HELLO";string new = test.Substring(0,1).ToUpper() + test.Substring(1,test.Length-1).ToLower();get new is "Hello"; 正则表达式我也不熟悉。随便写写。string strSrc = "show me the money"; StringBuilder sb = new StringBuilder(strSrc.Length); MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w\W]*)"); foreach (Match m in res) { sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value); } string strDst = sb.ToString(); MessageBox.Show(strDst); 贴错了。写好的,最后画蛇添足了一下。这个。下面的可以。string strSrc = "show me the money.during these days."; StringBuilder sb = new StringBuilder(strSrc.Length); MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)"); foreach (Match m in res) { sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value); } string strDst = sb.ToString(); MessageBox.Show(strDst); 非常感谢各位的回答,但我的意思是要将“HELLO,good,HoW ”一整句转成“Hello,Good,How ” 多写一行就可以了string strSrc = "Hello,Good,How";strSrc.ToLower();然后后面的都一样了。 string strSrc = "shOw mE tHe moNey.duRing theSe dAys."; strSrc = strSrc.ToLower(); StringBuilder sb = new StringBuilder(strSrc.Length); MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)"); foreach (Match m in res) { sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value); } string strDst = sb.ToString(); MessageBox.Show(strDst); 如果你希望包括换行符,就用下面这个正则MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?[\s]?)"); 再请问一句StringBuilder和MatchCollection要引用什么的? using System.Text;using System.Text.RegularExpressions; using System.Text;using System.Text.RegularExpressions; 求教 使用spread 5.0 怎么画柱形图 饼图 折线图 摄像头 程序 求这个正则表达式的匹配 hibernate的错误,网页报错Server Error in '/' Application. Process类调用cmd的问题 c#能写成c/s架构的winform程序么?要是能怎么发布呀? 请教using语句的使用场合 新手问题,怎样只打开一次mdi子窗体 求助C#+OpenGL+Tao 急...重绘控件拖动窗体时,只要控件部分被掩盖了就会出现残影这样的问题,请教好何解决!!! 紧急求救 菜单问题 50分请大家进来帮我看看我下面的代码错在那里呀!。。输出来的时候是空白的,什么也没有呀
string new = test.Substring(0,1).ToUpper() + test.Substring(1,test.Length-1).ToLower();get new is "Hello";
string strSrc = "show me the money";
StringBuilder sb = new StringBuilder(strSrc.Length);
MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w\W]*)");
foreach (Match m in res)
{
sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
}
string strDst = sb.ToString();
MessageBox.Show(strDst);
写好的,最后画蛇添足了一下。这个。下面的可以。
string strSrc = "show me the money.during these days.";
StringBuilder sb = new StringBuilder(strSrc.Length);
MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)");
foreach (Match m in res)
{
sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
}
string strDst = sb.ToString();
MessageBox.Show(strDst);
string strSrc = "Hello,Good,How";
strSrc.ToLower();
然后后面的都一样了。
strSrc = strSrc.ToLower();
StringBuilder sb = new StringBuilder(strSrc.Length);
MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)");
foreach (Match m in res)
{
sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
}
string strDst = sb.ToString();
MessageBox.Show(strDst);
MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?[\s]?)");
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;