Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 17th, 2005, 10:44 AM   #1
woodywellhung
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 woodywellhung is on a distinguished road
inserting text into a string

Hi everyone.

Can someone give me an idea as how to insert text into the middle of a string in C or C++?

I want to implement a simple find and replace function, that searches a string for a specified substring, and replaces it with another which could be of a different length.

Im really scratching my head on this one
woodywellhung is offline   Reply With Quote
Old Feb 17th, 2005, 11:12 AM   #2
Hockeyman
Programmer
 
Hockeyman's Avatar
 
Join Date: Jan 2005
Location: Vancouver, Canada
Posts: 60
Rep Power: 4 Hockeyman is on a distinguished road
Send a message via MSN to Hockeyman
The string.h library has quite a few functions for dealing with strings - you can search strings for specific characters or even substrings, replace chars or substrings etc...
A description of all these functions is here.
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~

Hockeyman is offline   Reply With Quote
Old Feb 17th, 2005, 2:43 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
The Standard Template Library is also a good source for such things... no need to reinvent the wheel.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Feb 17th, 2005, 3:35 PM   #4
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Yeah man, just go with STL... that is what it is there for... you could spend at least a good week writing a good string class and functions that even come close to doing what STL's string class can.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Feb 17th, 2005, 4:33 PM   #5
woodywellhung
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 woodywellhung is on a distinguished road
OK thanks guys I'll have a look at STL.
woodywellhung is offline   Reply With Quote
Old Feb 17th, 2005, 5:06 PM   #6
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 253
Rep Power: 4 melbolt is on a distinguished road
check this link out, i believe this is what you are looking for
String Members

basically, it's a list of all the member functions and what they do for the string class. check out the "Insert" member.
melbolt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC