C#怎样在匹配的字符串后面追加字符串。。。。。。。。

anan221 2008-07-05 10:28:14
C#怎样在匹配的字符串后面追加字符串。。。。。。。。
...全文
1230 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheng9hhd 2008-07-10
  • 打赏
  • 举报
回复
正则替换的时候加上
紫气东来_999 2008-07-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 root_ 的回复:]
Replace


无语,应用环境也不说,例子也不给,就这么凭空的一个问题。。。
[/Quote]
Feiin 2008-07-07
  • 打赏
  • 举报
回复
参考
string pattern = @"/Subject/";
string inputStr = @"/Subject/";
Regex reg = new Regex(pattern);
string outputStr = reg.Replace(inputStr, @"/Subject/2008/");
Response.Write(outputStr);
dqlfjy 2008-07-07
  • 打赏
  • 举报
回复
替换啊.
先用正则找到匹配字串,再用该字串加上你要追加的字串,组成新的字串,替换掉老的字串
lextm 2008-07-05
  • 打赏
  • 举报
回复
如果是用正则匹配,那么请看看Regex.Replace这个函数的帮助。
root_ 2008-07-05
  • 打赏
  • 举报
回复
Replace


无语,应用环境也不说,例子也不给,就这么凭空的一个问题。。。
chenz322556 2008-07-05
  • 打赏
  • 举报
回复
这个是偷懒的办法啦!没有仔细考虑 哈哈
protected void Page_Load(object sender, EventArgs e)
{
string str = "我爱看小说";
string strReplace = "小说";
string strAdd = ",好多小说";
str = str.Replace(strReplace, strReplace + strAdd);
Response.Write(str);
}
我们在使用WinForm中的TextBox的智能提示要使用到两个重要的TextBox属性, 一个是AutoCompleteMode,另一个是AutoCompleteSource。 AutoCompleteMode有四个值,分别是None,Append,Suggest,SuggestAppend。他们分别是:不给提示。最可能的匹配项自动追加到当前数据。产生由一个或多个建议完成字符串组成的下拉列表。最可能的匹配项自动追加到当前数据并产生由一个或多个建议完成字符串组成的下拉列表。 AutoCompleteSource属性允许您从一些系统源中进行选择,例如 FileSystem、HistoryList、RecentlyUsedList、AllUrl 和 CustomSource。如果选择 CustomSource,则必须向 AutoCompleteCustomSource属性提供一个字符串列表。 我们现在就开始 在VS中建一个新的项目,在From1中添加一个TextBox 并取名为TB_AutoComplete。再添加一个BackgroundWorker取名为bgWorker。 接下来的事都由代码完成。 public Form1() {     bgWorker.RunWorkerAsync();//打开异步操作,完成数据的读取     TB_AutoComplete.AutoCompleteMode = AutoCompleteMode.SuggestAppend; //最可能的匹配项自动追加到当前数据并产生由一个或多个建议完成字符串组成的下拉列表     TB_AutoComplete.AutoCompleteSource = AutoCompleteSource.CustomSource; //设置智能提示的源为自定义源    } AutoCompleteStringCollection GetDataFromDB() { AutoCompleteStringCollection ac = new AutoCompleteStringCollection(); string constr = "server=.;initial catalog=AutoComplete;integrated security=true"; //数据库连接 SqlConnection con = new SqlConnection(constr); string sql = "select * from AutoComplete" ; //我这里使用一个叫AutoComplete的数据库,数据库里有两个字段 一个ID,一个AutoComplete。用于存放智能提示的内容    SqwlCommand cmd = new SqlCommand(sql, con); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string text = reader.GetString(0); ac.Add(text); } con.Close(); } catch (Exception ee) { con.Close(); MessageBox.Show("程序出错了,错误原因是:\n" + ee.Message, "温馨提示"); } return ac; } 然后我们在设计页面中找到bgWorker 在他的DoWorkg事件中写入   private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { e.Result=GetDataFromDB(); } 在RunWorkerCompleted事件中写入 private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { TB_AutoComplete.AutoCompleteCustomSource = (AutoCompleteStringCollection)e.Result; } 这样我们的智能提示就完成 了 效果图看附件

61,826

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧