Help me with this task, please!

Nov 20, 2020 at 10:58pm
Insert in front of each exclamation mark in the specified line
coma.
How can I write a command to determine the exclamation mark? And what command can be used for this? Which command to use to insert a comma before an exclamation mark?
Nov 21, 2020 at 12:09am
Best is just use the cursor and , key
Nov 21, 2020 at 12:20am
Ahah, yes but I need to make it a program.
Nov 21, 2020 at 12:54am
Hello chebyrek,

What code do you have so far?

Is it a C or C++ program.

It is difficult to suggest anything when no one knows what you can do.

Andy
Nov 21, 2020 at 12:56am
Maybe OpenOffice, Pages or Word etc have a macro for doing that so try there maybe.
Nov 21, 2020 at 12:58am
Perhaps ask Siri :)
Nov 21, 2020 at 1:01am
Hi chebyrek,

I just asked Siri and mentioned your name thinking she would help. She didn't. All she said was "Fk off and do it yourself you lazy sh!t"

PS she didn't even put a comma in front of her exclamation mark - how rude was that,!
Nov 21, 2020 at 10:16am
Insert in front of each exclamation mark in the specified line coma.
How can I write a command to determine the exclamation mark? And what command can be used for this? Which command to use to insert a comma before an exclamation mark?


This is missing some info - such as what line?

However, if the required line is a string, then use.find() to find the ! and then .insert() to insert the ,


Last edited on Nov 21, 2020 at 10:17am
Nov 21, 2020 at 11:33am
seeplus, thanks!
Nov 21, 2020 at 12:46pm
To do this for all the ! in a string, consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>
#include <iostream>

const char fnd {'!'};
const char ins {','};

int main()
{
	std::string line = "123! qwerty! zxc!!";

	for (size_t ret = 0; (ret = line.find(fnd, ret)) != std::string::npos; ret +=2)
		line.insert(ret, 1, ins);

	std::cout << line << '\n';
}


which displays:


123,! qwerty,! zxc,!,!

Nov 21, 2020 at 5:27pm
Thanks for the advice)
Topic archived. No new replies allowed.