Re: My brains have gone dry and flakey - I can't get this to work!

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 12/07/04


Date: Tue, 7 Dec 2004 17:56:16 +1100


"Paul F. Johnson" <paul@all-the-johnsons.co.uk> wrote in message
news:cp1pv6$25j1$1@mimas.salford.ac.uk...
| Hi,
|
| Probably the simplest thing in the world, but for some reason, I can't
| get it to work. It's basically a search and replace.
|
| Take a string, whizz through it and for each occurence of a letter,
| replace it with the capital.
|
| What I have is this (it's a small test)

[snip]

| int main()
| {
| string test = "d-mmmm-y", dummy;
| for (int t = 0; t < test.length(); ++t)
| {
| if (test[t] == 'm')
| dummy.insert(t, "M", 0, 1)
| else
| dummy[t] = test[t];
| }
| cout << test << " : " << dummy << endl;
| }

[snip]

You have quite a few corrections pointed out to you
about your code already, so I won't repeat them, but
I have to ask the question, what's wrong with using
the standard library features for this task ?:

  # include <algorithm>
  std::replace( test.begin(), test.end(), 'm', 'M' );

Cheers.
Chris Val



Relevant Pages

  • Re: Other JSF options
    ... the point of firm positions of disagreement, so my comments below will be ... <snip stuff there is no use arguing further> ... Nor, AFAIR, did the GAO claim that the M60A3 was "inherently" a better tank ... And of course the reason, most of the reason for the current slip was the ...
    (rec.aviation.military)
  • Re: I know you guys would hate me for this....
    ... usually just snip them. ... the reason why we are responding to it, but merely responding for the sake ... of being sensitive to your cat. ... If Ranmao wants a hug, ...
    (rec.games.computer.ultima.dragons)
  • Re: OT:Thanksgiving
    ... tentative excuse, but not the reason. ... Our new government is founded upon exactly the opposite idea; ... the negro is not equal to the white man; that slavery - subordination to ...
    (comp.lang.cobol)
  • Re: This is absolutely GREAT!!!
    ... Randy, first you back off from one city. ...  That is the reason we have the mess we are in now. ...   you don't like that. ...
    (misc.transport.road)
  • Re: Javascript on the client as an alternative to Perl/PHP/Python on the server
    ... stored while the Internet connection is established and accessed later offline. ... requires CSS, image, JavaScript, Flash, Quicktime support etc. ... I included "not so sophisticated" for a reason. ...
    (comp.lang.javascript)