将 文本格式标记 转化为 html格式标记
在做一个聊天记录的时候遇到这样一个问题,之前写入的带有特殊标记的文字,在写入数据库再读取的时候,带有html标记,
在后台调试,设置断点,取出的数据(hgjghj)(包括样式),
用文本可视化查看 为 :<FONT color=#e6421a>hgjghj</FONT>
用HTML可视化查看 为:<FONT color=#e6421a>hgjghj</FONT>
在js中利用 document.getElementById ("newmessage").innerHTML = str;将str赋值给newmessage控件时,显示的一直是:<FONT color=#e6421a>hgjghj</FONT>
如果要去掉font标记 ,只显示hgjghj
解决方法如下:
将str赋值给控件前,先经过以下方法处理。
public static string newStr(string oldStr)
{
oldStr = oldStr.Replace(" ", " ");
oldStr = oldStr.Replace("<", "<");
oldStr = oldStr.Replace(">", ">");
oldStr = oldStr.Replace("<br/>", "\n");
oldStr = oldStr.Replace(" ", "\t");
oldStr = oldStr.Replace(""", "\"");
return newStr;
}
这时在
用文本可视化查看 为 :<FONT color=#e6421a>hgjghj</FONT>
用HTML可视化查看 为:hgjghj
此时前台控件显示的就将是hgjghj (保留样式,不显示标记)
如果要去掉所有标记,同时去掉样式, 只要在经过上面的方法处理之后,在经过以下方法即可
function RemoveHTML(strText)
{
var regEx = /<[^>]*>/g;
&nb
相关文档:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; char ......
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
Go
----截取字符串,并出去html
create FUNCTION [dbo].[CutString] (@str varchar(1000),@length int)
RETURNS varchar(1000) AS
BEGIN
declare @mainstr varchar(1000)
declare @substr varchar(1000)
if(@str is not null or @st ......
直接封装成一个类的,用起来还挺方便的
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text ......
string tent = this.TextBox_info.Text.Replace("<", "<").Replace(">", ">").Replace(" ", " ").Trim().Replace("\n", "<br/>");
& ......