modifying a string variable
I have a string variable which is named query
. It's value is:
select col1, col2 from tab1
inner join (select col3, col4 from tab2)
Would it be possible to apply a treatment to this string variable to replace the first appearance of select
with select top 100
?
The string variable should become:
select top 100 col1, col2 from tab1
inner join (select col3, col4 from tab2)
var query = "select col1, col2 from tab1 inner join (select col3, col4 from tab2)";
var regex = new Regex("select");
query= regex.Replace(query, "Select TOP 100", 1);
This will make sure to only replace the first instance, instead of all instances of select. It can also be easily modified if you need to change what you are replacing by changing the regex.
query = "SELECT TOP 100 " + query.Substring("SELECT ".Length)
要么:
query = query.Replace("select col1", "select top 100 col1");
链接地址: http://www.djcxy.com/p/68832.html
下一篇: 修改一个字符串变量