如何使用winform C#编程来查找和替换段落中的单词 [英] How to find and replace the word in a paragraph through programming using winform C#
问题描述
我有一个RichtextBox。它持有一句话,即亲爱的家长,你的病房今天还没来学校。
一个Gridview控件也可用于相同的形式,它包含3个列,即SrNo。,Student'sName&消息。
现在我想用句子中的双美元替换Student'sName。
我的Gridview就像
================================== =========
SrNo。 Student'sName消息
====================================== =====
1-姓名-1空白
2-姓名 - 2空白
3-姓名-3无空>
=============================================
更换后应该显示如下
=================== ================================================== ===============
Sr.No. Student'sName消息
====================================== ==============================================
1-姓名-1亲爱的家长,你的病房名字-1今天还没来学校。
2-姓名-2亲爱的家长,你的病房名字-2还没来学校今天。
3-姓名-3亲爱的家长,你的病房名字-3今天还没来学校。
============ ================================================== ======================
请给我打电话。
谢谢
我的尝试:
........................................
I have one RichtextBox. It is holding a sentence i.e. Dear Parents, Your ward $$ has not come to school today.
One Gridview control is also available on the same form and it is containing 3 Columns which is SrNo., Student'sName & Message.
Now I want to replace the Student'sName with double dollar where it is presenting in the sentence.
My Gridview is like
===========================================
SrNo. Student'sName Message
===========================================
1- Name-1 Null
2- Name-2 Null
3- Name-3 Null
=============================================
After replacement it should show lik e
====================================================================================
Sr.No. Student'sName Message
====================================================================================
1- Name-1 Dear Parents, Your ward Name-1 has not come to school today.
2- Name-2 Dear Parents, Your ward Name-2 has not come to school today.
3- Name-3 Dear Parents, Your ward Name-3 has not come to school today.
====================================================================================
Please helm me.
Thanks
What I have tried:
........................................
推荐答案
今天还没来学校。
一个Gridview控件也可以在同一个表单上使用它是包含3个列,即SrNo。,Student'sName&消息。
现在我想用句子中的双美元替换Student'sName。
我的Gridview就像
================================== =========
SrNo。 Student'sName消息
====================================== =====
1-姓名-1空白
2-姓名 - 2空白
3-姓名-3无空>
=============================================
更换后应该显示如下
=================== ================================================== ===============
Sr.No. Student'sName消息
====================================== ==============================================
1-姓名-1亲爱的家长,你的病房名字-1今天还没来学校。
2-姓名-2亲爱的家长,你的病房名字-2还没来学校今天。
3-姓名-3亲爱的家长,你的病房名字-3今天还没来学校。
============ ================================================== ======================
请给我打电话。
谢谢
我的尝试:
........................................
has not come to school today.
One Gridview control is also available on the same form and it is containing 3 Columns which is SrNo., Student'sName & Message.
Now I want to replace the Student'sName with double dollar where it is presenting in the sentence.
My Gridview is like
===========================================
SrNo. Student'sName Message
===========================================
1- Name-1 Null
2- Name-2 Null
3- Name-3 Null
=============================================
After replacement it should show lik e
====================================================================================
Sr.No. Student'sName Message
====================================================================================
1- Name-1 Dear Parents, Your ward Name-1 has not come to school today.
2- Name-2 Dear Parents, Your ward Name-2 has not come to school today.
3- Name-3 Dear Parents, Your ward Name-3 has not come to school today.
====================================================================================
Please helm me.
Thanks
What I have tried:
........................................
>
试试这个
try this
private void button1_Click(object sender, EventArgs e)
{
string text = richTextBox1.Text; //"Dear Parents, Your ward
今天还没来学校。 ;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string name = Convert.ToString(row.Cells [ 1 ]。Value) ;
if (!string.IsNullOrWhiteSpace(name))
row.Cells [ 2 ]。Value = text.Replace(
has not come to school today."; foreach (DataGridViewRow row in dataGridView1.Rows) { string name = Convert.ToString(row.Cells[1].Value); if (!string.IsNullOrWhiteSpace(name)) row.Cells[2].Value = text.Replace("
这篇关于如何使用winform C#编程来查找和替换段落中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!