473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replacing the second carriage return

I have a string with multiple carriage returns in it. I need to remove
the second carriage return but leave all the rest. Anyone know of a
function that will do this?

I've come up with this:

/***********************************************/

DECLARE @MyString varchar(100)

SET @MyString='Line one.
Line two.
Line three.
Line four.'

SELECT @MyString

SELECT @MyString = LEFT(@MyString, CHARINDEX(CHAR(13), @MyString,
CHARINDEX(CHAR(13), @MyString, 0)+1)-1)
+ RIGHT(@MyString, LEN(@MyString)-(CHARINDEX(CHAR(13), @MyString,
CHARINDEX(CHAR(13), @MyString, 0)+1)+1))

SELECT @MyString

/***********************************************/

However, if there is a less convoluted way of doing this, I'd love to
know.

Oct 6 '06 #1
1 3515
On 6 Oct 2006 12:46:15 -0700, as****@us.ci.org wrote:
>However, if there is a less convoluted way of doing this, I'd love to
know.
Hi asturt,

You can simplify it a bit using STUFF:

SELECT @MyString = STUFF(@MyString, CHARINDEX(CHAR(13), @MyString,
CHARINDEX(CHAR(13), @MyString, 0)+1), 2, '')

Note that the third (length) argument of the STUFF has to be 2, not 1,
because you have to replace both the CR and the LF.

--
Hugo Kornelis, SQL Server MVP
Oct 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yawnmoth | last post by:
so... i'm trying to remove all carriage returns in the input i get from GET, and am trying to replace them with three dots... however, this never seems to work... i'm still getting carriage...
3
by: Canes_Rock | last post by:
The information posted at: ...
7
by: Rob Meade | last post by:
Hi all, Been a long time since I've been here... /me waves to all.. Ok - my conundrum.. I have a form where a user can enter text and BB codes...for example:
4
by: Josh | last post by:
Hi, I'm using System.Data.DataSet.ReadXml to convert some xml from a webservice to a DataSet. The xml looks like: <?xml version="1.0"...
4
by: John | last post by:
Hi How can I replace characters like carriage return and double quotes from strings? Thanks Regards
2
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the...
6
by: Tbone | last post by:
I'm changing our order confimation from a plain text to HTML. The original setup of this had carriage returns between line items. These are not interpreted by HTML so all the line items run...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
6
by: Eli Silverman | last post by:
I am using a c# utility to create a Java function on our web pages. I am utilizing an object we created to retrieve a comment field from our SQL database and have the system throw the desired alert...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.