473,386 Members | 1,791 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,386 software developers and data experts.

Putting a string in another string

52
While the title of this seems easy i fear it might not be :\

I'm trying to have my program search through a string to find the character '-' when it finds it, it will look at the next character and based on what that is it will run a certain function.

i.e.
Expand|Select|Wrap|Line Numbers
  1.  if(string[i+1] == 'a'){
  2.             functiona(int i);
  3. }
  4.  
in the function i want it to replace the "-a" with a word chosen at random, here is where i run into an issue.

is there a way that i can have the word placed into the string and the rest of the characters in the string moved down accordingly?

so if my string was "hello -a world!" and i wanted to put something like "small" starting at the '-' the end result would be "hello small world" instead of "hello smallrld"

Thanks in advance for any advice :)

p.s. i apologize for the use of hello world... so overused.
Mar 12 '08 #1
4 1285
Banfa
9,065 Expert Mod 8TB
There is no standard library function to do this, you will have to hand code it.
Mar 13 '08 #2
Studlyami
464 Expert 256MB
That is if your using C (which it looks like you are). In C++ the string class has a find function and a insert function which would do what you want.
Mar 13 '08 #3
Shisou
52
unfortunately I am working in C so it looks like more work for me :P

Thanks for the help
Mar 15 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
strchr() anyone?

strchr returns the address of the first occurrance of the character in the string.

You get the index location by subtracting the address of the string from the address returned by srtrchr().
Mar 16 '08 #5

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

Similar topics

4
by: Stuart Palmer | last post by:
Hi everyone, I have a form with '/' in some of the field names, when I pass through to the next page the field name comes back as though it's been htmlencoded, so getting the value out of the...
25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
8
by: J.S. | last post by:
What are the pros and cons of putting the database connection information in a DLL? Also, how does one do it? ;-) Thanks, J.S. --
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
1
by: Little | last post by:
Could someone start me on putting in a table into this code, and some HTML tags. I would to make the table below the map and have a header at the top. Thanks for the help. """ Publisher example...
5
by: GG | last post by:
Any thoughts on designing classes wheather to throw the exception and the consumer has to capture it on try catch or wrap all the methods in a main method This is the wrap logic MainMethod{ bool...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
0
by: ck123456 | last post by:
hi all regarding my previous post of having a code like this g.DrawString(Input1.Text(n), big_font, Brushes.Black, x , y , and putting it in a listbox actually i am taking a data from a textbox and...
4
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.