Help me with this task, please!

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?
Best is just use the cursor and , key
Ahah, yes but I need to make it a program.
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
Maybe OpenOffice, Pages or Word etc have a macro for doing that so try there maybe.
Perhaps ask Siri :)
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,!
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
seeplus, thanks!
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,!,!

Thanks for the advice)
Topic archived. No new replies allowed.