如何使用winform C#通过编程替换单词# [英] How can I replace word through programming using winform C#

查看:58
本文介绍了如何使用winform C#通过编程替换单词#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个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:

..............................................

推荐答案

它在句子。



我有一个RichtextBox。它持有一句话,即亲爱的父母,你的病房和费用Rs。
" where it is presenting in the sentence.

I have one RichtextBox. It is holding a sentence i.e. Dear Parents, Your ward && fee Rs. "


尚未存入。



Gridview

================ ===========================

stdName |留言|需求

== =========================================

Rahul | 500 |

Sonu | 450 |

Monu | 600 |

=============== ==============================



更换后应该在需求栏中显示

====================================== ==========================================

需求

================================= ===============================================

亲爱的家长们,你的病房Rahul费用卢比。 500尚未存入。

亲爱的家长们,您的病房Sonu费用Rs。 450尚未存入。

亲爱的家长们,您的病房Monu费用Rs。 600尚未存入。

==================================== ====================================



我的尝试:



.................... ..........................
" 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:

..............................................


尝试:

Try:
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#通过编程替换单词#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆