Kau*_*nki 7 sql-server sql-server-2008
我有一栏供评论,我需要在一份报告中显示.这里发生了一些时间,用户使用多个进入评论框.我无法访问我只需要在SQL中管理这个东西的代码部分.
所以我删除了不需要的
1 /r/n
2 /n/n
Run Code Online (Sandbox Code Playgroud)
从使用
REPLACE(REPLACE(Desc, CHAR(13)+CHAR(10), CHAR(10)),CHAR(10)+CHAR(10), CHAR(10)) as Desc,
Run Code Online (Sandbox Code Playgroud)
现在我想删除任何\r或\n从开始或结束,如果任何字符串
此处使用 TRIM 检查
示例:UPDATE tablename SET descriptions = TRIM(TRAILING "<br>" FROM descriptions)
如果您想替换换行符,请使用如下所示的内容
SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')
Run Code Online (Sandbox Code Playgroud)
或者
DECLARE @testString varchar(255)
set @testString = 'MY STRING '
/*Select the string and try to copy and paste into notepad and tab is still there*/
SELECT testString = @testString
/*Ok, it seems easy, let's try to trim this. Huh, it doesn't work, the same result here.*/
SELECT testStringTrim = RTRIM(@testString)
/*Let's try to get the size*/
SELECT LenOfTestString = LEN(@testString)
/*This supposed to give us string together with blank space, but not for tab though*/
SELECT DataLengthOfString= DATALENGTH(@testString)
SELECT ASCIIOfTab = ASCII(' ')
SELECT CHAR(9)
/*I always use this like a final solution*/
SET @testString = REPLACE(REPLACE(REPLACE(@testString, CHAR(9), ''), CHAR(10), ''), CHAR(13), '') SELECT @testString
/*
CHAR(9) - Tab
CHAR(10) - New Line
CHAR(13) - Carriage Return
*/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19096 次 |
| 最近记录: |