这是我的做法,我觉得太复杂了,有没有更好的?谢谢MatchCollection regexForConvert = Regex.Matches( oldText, @"\bleft\b\s+\bjoin\b\s+(?<name>\w+)", RegexOptions.IgnoreCase );
foreach( Match subString in regexForConvert )
{
String name = subString.Groups["name"].ToString().ToUpper(); int index = oldText.IndexOf( subString.Value.ToUpper() );
int keyLength = index + subString.Value.ToUpper().Length;
int textLength = oldText.Length - keyLength;
if( index > 0 )
newText += oldText.Substring(0, index); newText += " " + name + ","; newText += oldText.Substring(keyLength, textLength); }
foreach( Match subString in regexForConvert )
{
String name = subString.Groups["name"].ToString().ToUpper(); int index = oldText.IndexOf( subString.Value.ToUpper() );
int keyLength = index + subString.Value.ToUpper().Length;
int textLength = oldText.Length - keyLength;
if( index > 0 )
newText += oldText.Substring(0, index); newText += " " + name + ","; newText += oldText.Substring(keyLength, textLength); }
解决方案 »
- Dictory<>泛型集合怎么排序
- 请教,c#查询Excel数据库包含字符
- winform 中 private static void 使用 textBox
- 重分求解!实现异形控件,一般用什么方法呢?急~~~~
- 包加载失败!!!help!!!
- AxAcroPDFLib.AxAcroPDF 的使用,很急!!
- 谁研究NHibernate亚,看了1周了没有头绪,从何看起?如何研究这个系统?已经看了张老三的文章,看不懂!
- 菜鸟求助一个正则表达式问题
- WPF,这个引用是怎么添加的?
- 如何取得远程(url)共享文件夹中的文件数目?
- 为什么ACCess超过二个访问数,程序就报错!
- 对于DataTable,如何实现数据的Group By功能?
if (s.ToLower().StartsWith("left")) s = s.Remove(0,9);
text = text.Replace( "left join customer", ",customer" ),
但是把"left join customerAddress" 也替换了,
请教有么比较通用的替换法,
strContent=Regex.Replace(strContent,
@"\bleft\b\s+\bjoin\b\s+\bcustomer\b",
"Customer",RegexOptions.IgnoreCase);
MessageBox.Show(strContent);