473,671 Members | 2,340 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 1971
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
2268
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 values and separators class { private string globalvar = ""; private void manipulate (whattodo ) //substring, join, etc....
4
2311
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 = "\231-3423/\453-1234/\231-3473/\231-3474/" //randomly pick a phone num from string. n = randomNum;
32
14838
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 ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
29
4302
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 substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can any tell me how I can implement such functionality in C#? 2. Is it possible to add/include function...
2
1963
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 = "\231-3423/\453-1234/\231-3473/\231-3474/" //randomly pick a phone num from string. n = randomNum;
4
3481
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 substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
9
4698
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 foo(); 2) I need to auto-add code to every method of particular class safeclass MyClass {
5
7482
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 20.02.2006 etc... And I want to replace the /,.etc character with - (as 20-02-2006)
2
2169
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 understanding how to go about this properly. For instance, the db column "myVal" is defined as a double in the db. In my table I want to display the value of that number by 1000. I used the code below and it does the trick. However, for some rows...
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2808
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 we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.