473,511 Members | 9,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

advanced string manipulation

hello again..
i want to design a program which takes in a string and replaces all 's'
characters with 'sh'. how do i do it? thanks a lot!

Oct 8 '06 #1
4 1965
MC felon wrote:
hello again..
i want to design a program which takes in a string and replaces all 's'
characters with 'sh'. how do i do it? thanks a lot!
What have you tried?

--
Ian Collins.
Oct 8 '06 #2
here's what i have tried:

cout<< "enter a string\n\n";

gets(take);

//calculation

int len = 0;

char temp[2];

len = strlen(take);

for(int g=0;g<len;g++)
{
while(take[g] != ' \0 ')
{
if(take[g] == 's')
{
//dont know what to do
}
}
}
cout<< take;
getch();
}

Oct 8 '06 #3
MC felon wrote:

In future, please a) quote some context in your reply and b) post
something that compiles on its own.
here's what i have tried:

cout<< "enter a string\n\n";

gets(take);
gets is vile (the root or most buffer overflows), avoid at all cost.
Use std::getline, which takes the maximum buffer size as a parameter.
//calculation

int len = 0;
Introduce len where it is assigned.
char temp[2];

len = strlen(take);

for(int g=0;g<len;g++)
{
while(take[g] != ' \0 ')
You don't want this inner loop, the for is already traversing take. Use
one or the other.
{
if(take[g] == 's')
{
You would be best to declare a second array, double the size of take and
copy the characters to this. Where take[g] == 's', add an 'h'.
//dont know what to do
}
}
}
cout<< take;
Should add << std::endl here.
getch();
why?

--
Ian Collins.
Oct 8 '06 #4

MC felon wrote:
here's what i have tried:

cout<< "enter a string\n\n";

gets(take);

//calculation

int len = 0;

char temp[2];

len = strlen(take);

for(int g=0;g<len;g++)
{
while(take[g] != ' \0 ')
{
if(take[g] == 's')
{
//dont know what to do
}
}
}
cout<< take;
getch();
}
What I see above (disregarding cout) is C code. So you have basically
two choices:

a) switch to the more appropriate std::string and return if you have
problems using that one.
b) Remove the line that couts take and ask at comp.lang.c. That group
will have all the expertise needed to deal with C and can give you a
much better answer.

/Peter

Oct 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2264
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
4
2304
by: Aaron | last post by:
I like like to randomly output phone numbers seperated by \ and / from a string s = "\231-3423/\453-1234/\231-3473/\231-3474/" private string GetPhoneNum() { s =...
32
14762
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
29
4277
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
2
1955
by: Aaron | last post by:
I would like to randomly output phone numbers seperated by \ and / from a string. s = "\231-3423/\453-1234/\231-3473/\231-3474/" //c sharp code private string GetPhoneNum() { s =...
4
3471
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
9
4678
by: Let_Me_Be | last post by:
Hi all, I'm developing a small defensive programming toolkit for my own projects. So, here are my questions. 1) Is it possible to move from something like this: SAFECALL(foo();) to __safecall...
5
7457
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or ...
2
2162
by: Mike Cain | last post by:
Hi, The Repeater control seems like exactly what I want to output rows of data from my database. However I need to do some manipulation to the data prior to it being output and I'm not...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.