473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1762
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

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

Similar topics

2
by: DesignGuy | last post by:
I need to replace everything between and including two snippets of HTML code, for example: </table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d <B><P> sfd sd fsdfs <br> ...
3
by: Epetruk | last post by:
If I have a snippet of javascript code like this: var str = "This is a snippet; str.replace(/ */gi,' '); what should the call to replace do? My actual tests show that it inserts spaces...
16
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: ...
6
by: localhost | last post by:
I have a string that looks like this: "document.form1.textBox1.focus ();document.form1.textBox1.select();" I want to replace the text between "document.form1." and ".focus()", as well as...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
4
by: Neo Geshel | last post by:
Greetings I am using VB in my ASP.NET project that uses an admin web site to populate a database that provides content for a front end web site. I am looking for a way to use replace() to...
5
by: sophie_newbie | last post by:
OK this might seem like a retarded question, but what is the difference between a library and a module? If I do: import string am I importing a module or a library? And if i do...
3
by: Brad | last post by:
I see the use of Javascript replace all over the web. What are all the character sequences? (sorry I am a bit of a newbie at this). i.value.replace(/+/g, ''); I understand that /g is global...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
3
by: MB | last post by:
I need to replace all occurances of a certain character located between two tags. I have included an example of what i have come up with so far, but it doesn't work they way I want it to: str =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.