Replacing part of String

closed account (EUqDSL3A)
I want to replace part of string

ex.
I have this string
turd!turd.turd.456.tird

I want to remove anything past the ! (and the exclamation point itself) and return it back to the user
as
turd

how can I search for the ! and remove everything after that

Last edited on
Can you change your user name please - It means something very
disgusting in English (or maybe you already know that??)
Last edited on
closed account (EUqDSL3A)
I wasn't aware that I could change it, I'll change it once I find the setting.

But on topic, you have any idea on how I can accomplish this?
assuming we are talking about c++ strings - then string has some find member functions.
Like find, find_first_of, find_first_not_of
Check out the reference documentation on this site.

You can use ( a suitable one of these) to find the position of the !.

You can use the substr member function to extract the substring.

closed account (EUqDSL3A)
Q:
assuming we are talking about c++ strings


A:
Replacing part of String
<-- title


Q:
You can use the substr member function to extract the substring.


A:
I know methods how to replace strings


well like I said, I know how to do that already, what I need

how can I search for the ! and remove everything after that

have you looked at the find_first_of function?
See here
http://www.cplusplus.com/reference/string/string/find_first_of/

Can't you put the two together??

1. use find_first_of function to find the position of the ! within the original_string.
2. use substr function to get the substring (starting at position 0 to the point where the ! was found).

3. reassign the substring to the original_string. (original_string = substring).

straightforward.
<-- title

The title gives no indication as to whether you're talking about string objects, or C-strings.
Topic archived. No new replies allowed.