用< br>替换/ n请帮忙
大家好,
我有一个textarea控件。我把它的价值放在一封html电子邮件中。
问题是新行被忽略了。我想取一个
控制值并用html< br>
标记替换任何换行回车。我尝试了以下功能,但它不起作用。有没有人有什么想法如何实现这个?提前致谢。 ~CK
string getComments()
{
string s = tbxComments.Text;
正则表达式r =新正则表达式(" / \ n / g");
s = r.Replace(s," < br />");
返回s;
}
Hi all,
I have a textarea control. I am putting it''s value in an html email. The
problem is that the new lines are being ignored. I want to take the
controls value and replace any newline carriage returns, with an html <br>
tag. I tried the following function but it doesn''t work. Does anyone have
any ideas how to accomplish this? Thanks in advance. ~ CK
string getComments()
{
string s = tbxComments.Text;
Regex r = new Regex("/\n/g");
s = r.Replace(s, "<br/>");
return s;
}
你有没有尝试更换chr(10)和chr(13)而不是\ n?
-
Swanand Mokashi
Microsoft认证解决方案开发人员(.NET) - 早期成就者
Microsoft认证应用程序开发人员(.NET)http://www.dotnetgenerics.com/
DotNetGenerics.com - 关于Microsoft .NET的所有内容/>
技术......
http:// www .swanandmokashi.com /
http://www.swanandmokashi.com/HomePage/WebServices/
股票报价的主页,当日报价和星座网络服务
" CK" c为C _ ********** @ hotmail.com>在消息中写道
news:jJ ******************* @ newssvr27.news.prodigy。 net ...
Have you tried replacing chr(10) and chr(13) instead of \n ?
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)
http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"CK" <c_**********@hotmail.com> wrote in message
news:jJ*******************@newssvr27.news.prodigy. net...
大家好,
我有一个textarea控件。我把它的价值放在一封html电子邮件中。
问题是新行被忽略了。我想使用
控件值并使用html< br>
标记替换任何换行符回车符。我尝试了以下功能,但它不起作用。有没有人有任何想法如何实现这一目标?提前致谢。 ~CK
字符串getComments()
字符串s = tbxComments.Text;
正则表达式r = new正则表达式(" / \ n / g");
s = r.Replace(s,"< br />");
return s;
}
Hi all,
I have a textarea control. I am putting it''s value in an html email. The
problem is that the new lines are being ignored. I want to take the
controls value and replace any newline carriage returns, with an html <br>
tag. I tried the following function but it doesn''t work. Does anyone
have any ideas how to accomplish this? Thanks in advance. ~ CK
string getComments()
{
string s = tbxComments.Text;
Regex r = new Regex("/\n/g");
s = r.Replace(s, "<br/>");
return s;
}
我使用的是c#而不是VB。 c#是否使用chr()函数?我不认为
所以。
还有其他任何想法吗?
Swanand Mokashi < SW *********** @ swanandmokashi.com>在消息中写道
新闻:eF ************* @ TK2MSFTNGP02.phx.gbl ...
I am using c# and not VB. Does c# use the chr() function? I do not think
so.
Any other ideas?
"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:eF*************@TK2MSFTNGP02.phx.gbl...
你有没有尝试更换chr( 10)和chr(13)而不是\ n?
-
Swanand Mokashi
微软认证解决方案开发人员(.NET) - 早期成就者
微软认证Application Developer(.NET)
http://www.dotnetgenerics.com /
DotNetGenerics.com - 关于Microsoft .NET
技术的任何事情......http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
股票报价的主页,当日报价和星座网络服务
" CK" c为C _ ********** @ hotmail.com>在消息中写道
新闻:jJ ******************* @ newssvr27.news.prodigy。 net ...
Have you tried replacing chr(10) and chr(13) instead of \n ?
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)
http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"CK" <c_**********@hotmail.com> wrote in message
news:jJ*******************@newssvr27.news.prodigy. net...
大家好,
我有一个textarea控件。我把它的价值放在一封html电子邮件中。
问题是新的行被忽略了。我想用
控件值并用html取代任何换行符回车,
< br>标签。我尝试了以下功能,但它不起作用。是否有人有任何想法如何实现这一目标?提前致谢。 ~CK
字符串getComments()
字符串s = tbxComments.Text;
正则表达式r = new正则表达式(" / \ n / g");
s = r.Replace(s,"< br />");
return s;
}
Hi all,
I have a textarea control. I am putting it''s value in an html email.
The problem is that the new lines are being ignored. I want to take the
controls value and replace any newline carriage returns, with an html
<br> tag. I tried the following function but it doesn''t work. Does
anyone have any ideas how to accomplish this? Thanks in advance. ~ CK
string getComments()
{
string s = tbxComments.Text;
Regex r = new Regex("/\n/g");
s = r.Replace(s, "<br/>");
return s;
}
CK< c _ **** ******@hotmail.com>写道:
CK <c_**********@hotmail.com> wrote:
我有一个textarea控件。我把它的价值放在一封html电子邮件中。
问题是新行被忽略了。我想使用
控件值并使用html< br>
标记替换任何换行符回车符。我尝试了以下功能,但它不起作用。有没有人有任何想法如何实现这一目标?提前致谢。 ~CK
字符串getComments()
{/>字符串s = tbxComments.Text;
正则表达式r =新的正则表达式(" / \ n / g") ;
s = r.Replace(s,"< br />");
返回s;
}
I have a textarea control. I am putting it''s value in an html email. The
problem is that the new lines are being ignored. I want to take the
controls value and replace any newline carriage returns, with an html <br>
tag. I tried the following function but it doesn''t work. Does anyone have
any ideas how to accomplish this? Thanks in advance. ~ CK
string getComments()
{
string s = tbxComments.Text;
Regex r = new Regex("/\n/g");
s = r.Replace(s, "<br/>");
return s;
}
首先要做的事情(IMO)是在不必要的情况下摆脱使用常规的
表达式。我不是一个正则表达式的专家,所以我不会告诉你,如果上面没有找到它是什么
你会期望它 - 但我*知道以下会做什么
你会期望它:
string replace = tbxComments.Text.Replace(" ; \ n","< br />");
现在,这只涉及换行,而不是回车 - 但是你
之后可以随时删除所有回车。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet
如果回复小组,请不要给我发邮件
The first thing to do (IMO) is to get rid of the use of regular
expressions when they''re unnecessary. I''m not a regex expert, so I
couldn''t tell you without looking it up whether the above does what
you''d expect it to - but I *do* know that the following will do what
you''d expect it to:
string replaced = tbxComments.Text.Replace ("\n", "<br />");
Now, that only deals with line feeds, not carriage returns - but you
could always remove all carriage returns afterwards.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too