Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i Remove \n (Char(10)) from specific string from starting & Ending of the string in ms sql

I have one column for comment and I need to show this for one report. Here what happen some time, users uses multiple enters in comment box. I can not access code part I need to manage this thing in SQL only.

So I have removed unwanted

1 /r/n 
2 /n/n

from using

REPLACE(REPLACE(Desc, CHAR(13)+CHAR(10), CHAR(10)),CHAR(10)+CHAR(10), CHAR(10)) as Desc,

Now I want to remove any \r or \n from starting or ending of the string if any

like image 513
Kaushik Thanki Avatar asked Jan 05 '15 07:01

Kaushik Thanki


People also ask

How to remove first n characters from a string in Excel?

1. Remove first N characters with formula/UDF 2. Remove last N characters with formula/UDF 3. Batch remove N characters from left or right or mid without formulas 4. Download sample file 1. Remove first N characters with formulas In this part, I introduce three different ways to quickly remove first N characters from a string.

How do I remove a string from the start and end?

If you only need to remove something from the start and end only, you should use the str.strip () method. The str.replace () method two arguments as input, first is the character or string you want to be replaced, and second is the character or string you want to replace with.

Can we remove all Char(10) and Char(13) from a string?

We can not remove all char (10) or char (13) . For Example " ABCXYZ " Consider here before ABC we have char (10) or char (13) then only we need to replace it. same WAY if it's at end of the string after XYZ then only we need to perform replace for char (10) or char (13) .

How to remove characters from a string in Python?

Now let’s learn how to use the Python string .translate () method to do just this. Similar to the example above, we can use the Python string .translate () method to remove characters from a string. This method is a bit more complicated and, generally, the .replace () method is the preferred approach.


1 Answers

By the way you meant in your question:(Remove char(10) or char(13) from specific string)
Note: You should see the output result by switching your resultset output to Results to Text(Ctrl+T).

Results to Text

Results to Ttext:

Results to Grid

Results to Grid:

like image 149
knkarthick24 Avatar answered Sep 29 '22 19:09

knkarthick24