473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to Replace CR\LF

Hi.

I have the following string:

string s = "hello\W\n";

If I do this: std::cout << s; i would get "helloW"
How can I replace the \ within the string, so when I print it out, I
would get:

"hello\W"??

I tried like this:
string backslash ="\\";
unsigned int loc = 0;
do{
loc = until_regex.find( backslash[0], 0 );
if ( loc == string::npos)
break;
until_regex.replace( loc, 2,"A" );
}while( loc != string::npos );

but no luck.

Jul 23 '05 #1
3 3637
The \ before the W is dropped at compile time. You need to escape it in
the declaration of s:
string s = "hello\\W\n";

Jul 23 '05 #2
Well , yes i know that the \ before W is escaped.
But the problem is that s is a user input, representing a
regexp

If i would have a regexp like this:
s = "\w+\W*"

the user should input something like:
s= "\\w+\\W*"
which would become confusing, since the \ in regexp needs to be escaped
too.

Jul 23 '05 #3

gr****@gmail.com wrote:
Well , yes i know that the \ before W is escaped.
But the problem is that s is a user input, representing a
regexp

If i would have a regexp like this:
s = "\w+\W*"

the user should input something like:
s= "\\w+\\W*"
which would become confusing, since the \ in regexp needs to be escaped too.


No. The need to escape \ exists only at compile-time. I.e. when
it occurs in your .cpp. Users can just enter a single \ and this
will appear as a single char in your std::string. If they use the
TAB key, you'll get the single char '\t' in your std::string. The
'\"' char can also be entered with a single keystroke (on most
keyboards). OTOH, some keyboards need multiple keystrokes to
enter a single accented char like ä (which for me is "+a)

Regards,
Michiel Salters

Jul 23 '05 #4

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

Similar topics

4
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning...
5
by: McKirahan | last post by:
I'd like to use regular expressions to remove extraneous Carriage Return Line Feeds (CrLf) from a textarea before the form is submitted. I'd like to remove all trailing CrLf's and convert all...
5
by: WC Justice | last post by:
I have a database-driven web site that uses SQL Server for the back end, ASP for the wide front end and Access for the local front end. I have nvarchar fields that sometimes include paragraph...
3
by: Jon | last post by:
Hi... I'm getting stumped over the something that MUST be simple...basically, I'm trying to replace the characters 0D0A with a crlf, using Regex.Replace(). The problem is, the replaced string...
1
by: Jack Wright | last post by:
Dear All, In a multiline field if I enter the following way: Mangesh Anant Kodilkar There is a carriage return after each word. Now when I press save,it loses the CRLF characters. This is not...
2
by: Michael Persaud | last post by:
Hi All, Im trying to have a few strings presented in a LABEL. However the CRLF is not working. eg str = str1 + crlf + str2 + crlf + str3 label.text= str Do i need to declare the crlf as a...
2
by: Andrew | last post by:
Hello. I am working with very large files in my .NET project (1 million plus records). Some of these files do not have crlf's, which makes it very hard to read the file without a layout or record...
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...
10
by: Bob Quintal | last post by:
I'm receiving data in text files from a unix sustem that onlu puts a Lf character at the end of each row. Access insists on Cr or CrLf or it sees the file as 1 row 700Kb wide and chokes. Is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.