473,785 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing a quote by a "\n" ...

Hi !

I wonder how I can replace a quote by a "\n" in a string.

For example my string is rrrrrrr'ttttttt and I want to obtain :

rrrrrrr
ttttttt

I tried the function find, but I don't know how to specify in its
parameters the quote character.

Thanks guys !
Nov 27 '07 #1
8 1942
On 2007-11-27 17:54, Choi wrote:
Hi !

I wonder how I can replace a quote by a "\n" in a string.

For example my string is rrrrrrr'ttttttt and I want to obtain :

rrrrrrr
ttttttt

I tried the function find, but I don't know how to specify in its
parameters the quote character.
Does not "'" work?

--
Erik Wikström
Nov 27 '07 #2
Thanks for your answer, but it did not work ... Have you got another
idea Erik ?


On 27 nov, 18:07, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-11-27 17:54, Choi wrote:
Hi !
I wonder how I can replace a quote by a "\n" in a string.
For example my string is rrrrrrr'ttttttt and I want to obtain :
rrrrrrr
ttttttt
I tried the function find, but I don't know how to specify in its
parameters the quote character.

Does not "'" work?

--
Erik Wikström
Nov 27 '07 #3
Choi:
I wonder how I can replace a quote by a "\n" in a string.

For example my string is rrrrrrr'ttttttt and I want to obtain :

rrrrrrr
ttttttt

We call that an apostrophe in my part of the world (as opposed to an
inverted comma). I don't know if there's a char replacement function in
the Standard, but it's trivial to write:

void Replace(char *p,char const before,char const after)
{
assert(p); assert(before);

for (; p = strchr(p,before ); *p++ = after);
}

--
Tomás Ó hÉilidhe
Nov 27 '07 #4
Eric Viloin wrote:
Thanks for your answer, but it did not work ... Have you got another
idea Erik ?
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>
Nov 27 '07 #5
On 27 Nov., 17:54, Choi <Evil.C...@gmai l.comwrote:
Hi !

I wonder how I can replace a quote by a "\n" in a string.

For example my string is rrrrrrr'ttttttt and I want to obtain :

rrrrrrr
ttttttt

I tried the function find, but I don't know how to specify in its
parameters the quote character.

Thanks guys !
How about using std::replace? I wonder why noone have suggested that
before?

std::replace(st r.begin(),str.e nd(),'\'','\n') ;

/Peter
Nov 27 '07 #6
On Nov 27, 6:07 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2007-11-27 17:54, Choi wrote:
I wonder how I can replace a quote by a "\n" in a string.
For example my string is rrrrrrr'ttttttt and I want to obtain :
rrrrrrr
ttttttt
I tried the function find, but I don't know how to specify in its
parameters the quote character.
Does not "'" work?
std::find, on a string, will want something that is a char, or
convertible to a char. "'" is an array.

What he needs is '\''. (More generally, I'd write "\'" as well.
For reasons of orthorgonality, I always escape both " and ',
both in strings and in character constants.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 28 '07 #7
On Nov 27, 6:25 pm, "Alf P. Steinbach" <al...@start.no wrote:

[...]
Again, re optimization: std::string is not well suited for string
handling. It's not even well suited for passing strings around,
technically. But it's standard, and that's one great plus point, so
great that std::string is the default choice for that.
As a summary of std::string, this is actually pretty good. But
to be fair: std::string does define both the copy constructor
and an assignment operator---what else do you need for passing
strings around?
However, if optimization is required, consider some other
string class first, instead of fiddling with std::string-based
code.
More generally: don't use fundamental library types as part of
your application level abstraction. If your abstraction deals
with text, for example, don't use std::string for that text; use
some user defined class. A class which almost certainly uses
std::string in its implementation, at least until the profiler
says otherwise, but a class which defines very exactly the
interface you need. This is a good general rule, as it keeps
your options open. Use std::string directly, or a typedef to
std::string, and you're locked in; use a user defined class with
a narrower interface, and you can change the implementation in
any way that conforms to the interface.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 28 '07 #8
On Nov 28, 4:01 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
On Nov 27, 6:25 pm, "Alf P. Steinbach" <al...@start.no wrote:
[...]
Again, re optimization: std::string is not well suited for string
handling. It's not even well suited for passing strings around,
technically. But it's standard, and that's one great plus point, so
great that std::string is the default choice for that.
As a summary of std::string, this is actually pretty good. But
to be fair: std::string does define both the copy constructor
and an assignment operator---what else do you need for passing
strings around?
Efficiency, safety and possibly more information.
Most of these really concern creation of strings, rather than
just "passing them around". One point, however:

[...]
- being able to avoid copying for forming substrings
This is a deficiency in most current implementations , but is not
necessary according to the standard. An implementation more or
less like that of Java could be used, in which you don't need a
copy for substrings.

[...]
- e.g. character set.
Achieving this "normality" (what one naturally expect of a
string type, unless exposed to std::string for too long...)
needs a new string interface.
Having had to deal with "bad" string types in other languages
(in the past), I don't naturally expect very much:-). (Or is
that I naturally don't expect very much?)

The lack of information concerning the encoding (character set)
is an awkward problem. It is one, however, that we're used to
dealing with: it affects a lot of other types as well. (Is that
double meters, or millimeters? Is that Decimal Euros, or
Pounds?)

In the end, I think we need both: a "raw" type, for cases where
the "units" are implicitly known, and a more complete type which
associates a unit with each value. (Note that I'm not talking
here about typing issues, where the user assigns a double
representing meters to a variable containing the weight. That's
a different problem---which probably needs solving as well.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 29 '07 #9

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

Similar topics

3
3165
by: ribchr00 | last post by:
Hi all, I would like to replace line breaks such '+' with '<br />'. Easy task. Problems start when I try to only replace lines that do not end with HTML tags. I tried preg_replace("/+/", "<br />\n") but this does not seem to work. An example to better understand what I would like to achieve: first line
0
1716
by: BenO | last post by:
Hi I'm new to python and need to write a function to replace certain characters in a string (html). The characters I need to replace come from MS Word copy & paste and are: ' (Left quote) ' (Right quote) Double Left quotes
0
2112
by: Dimitris | last post by:
Hi folks... I am using the latest version of phpMyAdmin (2.5.5-pl1). Everything worked fine, until I tried running a few queries to change the character set. The queries did run, but ever since nothing SQL-wise works, because quotes are inserted with an artificial backslash (\). For example,
6
6608
by: Dan | last post by:
I wish to replace all the occurrances of " with &quot; within a string. I have tried using myString.Replace("\"", "&quot;"), but this does not work Any suggestions will be greatly appreciated Thanks
4
24358
by: Kevin Thomas | last post by:
Hi there, If I have a string var, strFoo that contains double-quotes such that it looks like this: I "love" VB What do I pass into the "replace" method to replace the double-quotes with something else? strFoo = strFoo.replace(???,"&quot;")
16
4929
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
6
325
by: shashi | last post by:
dim str as string str=" Barinova said “We exploit short-term inefficiencies in the world markets,†"
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
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 we have to send another system
3
2893
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.