字符串替换 [英] string replace

查看:103
本文介绍了字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是.net的新手.
如何替换字符串,这意味着当我在TextBox中输入一些文本并且要从数据库中检索值时,我想通过在结果中突出显示该文本来显示在TextBox中输入的内容.

我该怎么做?

Hi,

I am new to .net.
How can I replace a string, that means when I enter some text in a TextBox and I am retrieving a value from database, I want to display what I entered in the TextBox by highlighting that text in the result.

How can I do that?

推荐答案

试试看:

Try this:

String toHighlight = textBoxX.Text;
String dataFromDatabase = GetDBResult(); //I assume reading from the DB was not part of your problem
String startHighlightTag = "<span class=\"highlight\">"
String endHighLighTag = "</span>";

String dataToRender = dataFromDatabase.Replace(toHighlight, startHighLightTag + toHighLight + endHighlightTag);

//output dataToRender to a div or whatever



您必须对类突出显示有一些CSS定义,以便突出显示看起来完全符合您的要求.

干杯

曼弗雷德(Manfred)



You''ll have to have some CSS definition for the class highlight so that the highlighting looks exactly as you want.

Cheers

Manfred


这篇关于字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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