469,275 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Replace Between

3
Hello,

I should tell you I don't know much about C++ before i get started.

Ok, what I need is a way to replace some letters between the marks i choose.

For example:

string str1 = "whatsup<1>the string<2>hello";

I call a function that replaces everything between "<1>" and "<2>" with "is gone".

str1 now becomes "whatsup<1>is gone<2>hello";

the length of the string will always be different and so i can't just tell it to start removing at some static position from the start.

What I came up with is maybe make a loop that goes over each letter in the string and looking for <1> while counting how many letters have past and then count the distance between <1> and <2>. Delete the letters between those two some how and then use some replace method with the "position where to start replacing" method and replace the blank spot between the two.

But then again I might be an idiot so please give me some ideas.
May 19 '10 #1
2 1501
hype261
207 100+
Below is a link to a reference on the string class in C++. If I were you I would take a look at the find and replace methods that you can use for string manipulation.


http://www.cplusplus.com/reference/string/string/
May 19 '10 #2
whodgson
542 512MB
C++ has a number or functions for manipulating strings.e.g.
Expand|Select|Wrap|Line Numbers
  1. string s="ABCDEFGH"
  2. s1=s.erase(4,2)//s1=ABCDGH
  3. s2=s1.replace3,2,"xyz")//s2=ABCxyzH
Any text book will cover this.
May 20 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by DesignGuy | last post: by
3 posts views Thread by Epetruk | last post: by
6 posts views Thread by localhost | last post: by
4 posts views Thread by Neo Geshel | last post: by
5 posts views Thread by sophie_newbie | last post: by
3 posts views Thread by Brad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.