问题描述
有一个DataGridView。它有三列(stdName,Demand,Msg)
现在我想用&&替换stdName它带有$$的需求,并在句子中显示。
我有一个RichtextBox。它持有一句话,即亲爱的父母,你的病房&&费用卢比。 $$尚未存入。
Gridview
================ ===========================
stdName |消息|需求
========================================= ==
Rahul | 500 |
Sonu | 450 |
Monu | 600 |
======================================== =====
更换后应在需求栏中显示
============= ================================================== =================
需求
================ ================================================== ==============
亲爱的家长们,你们的病房Rahul费用卢比。 500尚未存入。
亲爱的家长们,您的病房Sonu费用Rs。 450尚未存入。
亲爱的家长们,您的病房Monu费用Rs。 600尚未存入。
==================================== ====================================
我的尝试:
.................... ..........................
There is one DataGridView. It has three columns (stdName, Demand, Msg)
Now I want to replace the stdName with "&&" and Demand with "$$" where it is presenting in the sentence.
I have one RichtextBox. It is holding a sentence i.e. Dear Parents, Your ward && fee Rs. "$$" has not been deposited.
Gridview
===========================================
stdName | Message | Demand
===========================================
Rahul | 500 |
Sonu | 450 |
Monu | 600 |
=============================================
After replacement it should show in demand column
================================================================================
Demand
================================================================================
Dear Parents, Your ward Rahul fee Rs. 500 has not been deposited.
Dear Parents, Your ward Sonu fee Rs. 450 has not been deposited.
Dear Parents, Your ward Monu fee Rs. 600 has not been deposited.
========================================================================
What I have tried:
..............................................
推荐答案
string template = myRichTextBox.Text;
foreach (DataGridViewRow row in myDataGridView2.Rows)
{
string demand = template;
object stdName = row.Cells["stdName"].Value;
object message = row.Cells["Message"].Value;
if (!string.IsNullOrWhiteSpace(demand) && stdName != null && message != null)
{
demand = demand.Replace("&&", stdName.ToString());
demand = demand.Replace("
这篇关于如何使用winform C#通过编程替换单词#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!