public string NoHTML(string Htmlstring) //去除HTML標記
{
//刪除腳本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//刪除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
❷ 如何用SQL語句,在數字加中文的混合數據中提取出中文
是Oracle資料庫嗎?
可以用截取字元串的函數。
select
Substr(欄位,1,INSTR(欄位,'/')-1)
from
al
例如
select
Substr('sdhfuiasdh/asdfsadf',1,INST('sdhfuiasdh/asdfsadf','/')-1)
from
al
❸ sql如何獲取字元串中的指定字元
1、創建測試表,
create table test_int(value varchar2(50));
❹ sql 表中一個欄位含有大量的中文字元,怎麼替換掉
意思是不顯示中國字唄,那就不用能顯示中國字的電腦編碼系統
❺ 跪求各位大俠!怎樣提取sql欄位存儲的字元串中的單個字元
我這里由一個存儲過程可以把逗號前面第一個詞取出來,你用個循環就可以把所有的都取出來了
CREATE
PROCEDURE
PopFirstWord
@SourceString
NVARCHAR(4000)
=
NULL
OUTPUT,
@FirstWord
NVARCHAR(4000)
=
NULL
OUTPUT
AS
SET
NOCOUNT
ON
DECLARE
@Oldword
NVARCHAR(4000)
DECLARE
@Length
INT
DECLARE
@CommaLocation
INT
SELECT
@Oldword
=
@SourceString
IF
NOT
@Oldword
IS
NULL
BEGIN
SELECT
@CommaLocation
=
CHARINDEX(',',@Oldword)
SELECT
@Length
=
DATALENGTH(@Oldword)
IF
@CommaLocation
=
0
BEGIN
SELECT
@FirstWord
=
@Oldword
SELECT
@SourceString
=
NULL
RETURN
0
END
SELECT
@FirstWord
=
SUBSTRING(@Oldword,
1,
@CommaLocation
-1)
SELECT
@SourceString
=
SUBSTRING(@Oldword,
@CommaLocation
+
1,
@Length
-
@CommaLocation)
RETURN
@Length
-
@CommaLocation
END
RETURN
0
❻ SQL語句提取出中文的拼音首字母
正好最近收藏了一個 你可以看下思路
--將中文字元串轉化成文字首拼音的組合
create function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非漢字字元,返回原字元
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
--函數調用實例:
select dbo.fun_getPY('中華人民共和國AAA01')
/*
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZHRMGHGAAA01
(1 行受影響)
*/
❼ sqlsever中消除記錄中的中文,提取非中文字元
建立函數來處理吧。
createfunctionfun_del_zh
(@colvarchar(1000))
returnsvarchar(1000)
AS
begin
declare@returncharvarchar(1000),@lenint
select@returnchar='',@len=1
while(@len<=len(@col))
begin
if(ASCII(substring(@col,@len,1))<122)
set@returnchar=@returnchar+substring(@col,@len,1)
set@len=@len+1
end
return@returnchar
end
go
selectid,dbo.fun_del_zh(name)nmfromtest;
idnm
test test
test1 test
test2 test2
有問題再追問。
❽ SQL語句查詢返回字元串中中文字元前的字元(包含數字與字母)
select substring(field1,1,patindex('%[吖-咗]%',field1)-1) from table
❾ sql語句中有中文,符號等怎麼處理
對於特殊字元
要用到轉義符
name like '%\%%' escape '\'意思就是保留\後面的一個字元,無視\
就是name中包含%的記錄
你給幾個改完的欄位的例子阿
比如說'你好(%><;'i9hh %()'你要改成怎樣
『你不好%*#@)%』這個又要改成怎麼
❿ 如何解決SQL語句中含有中文字元無法查詢
package oop.hu.ytu.;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import oop.hg.ytu.beans.LoginBean;
import oop.hg.ytu.utils.JdbcUtils;
/**
* 處理用戶登錄請求
* @author Administrator
*
*/
public class LoginDomain {
public LoginBean select(String tableName,String username){
Connection con = null;
PreparedStatement pt = null;
ResultSet rs = null;
LoginBean bean = new LoginBean();
try {
username = "\""+username+"\"";
con = JdbcUtils.getConnection();
String sql = "select name,password from "+tableName+" where name="+username+"";
pt = con.prepareStatement(sql);
// pt.setString(1, tableName);
// pt.setString(2, u);
rs = pt.executeQuery();
while(rs.next()){
bean.setUsername(rs.getString("name"));
bean.setPassword(rs.getString("password"));
}
} catch (Exception e) {
throw new RuntimeException(e);
}finally{
JdbcUtils.free(rs, pt, con);
}
return bean;
}
}
username = "\""+username+"\"";這句話是進行字元串處理,加上雙引號。
<pre name="code" class="java" style="background-color: rgb(255, 255, 255); ">String sql = "select name,password from "+tableName+" where name="+username+"";
這句話是重點,一定不能使用PreparedStatement提供的字元串處理方法,一定要直接自己拼接出字元串來運行,這樣對於中文的處