Hello, how would i go about achieving the following requests. I am new to this. Can i achieve all the results from once class or calling different classes. Im'm not sure if I have asked the questions correclty. Please help. Here is want i need to accomplish.
Write a program "StringManipulation.cs" in C# which accepts
two strings as command line arguments. The program should do the following:
i) print and display the total number of occurrences of the character „a? or
„A? present in both the strings
ii) replace every occurrence of „a? or „A? with @
iii) convert both the strings to upper case
iv) concatenate the two strings and display the result
Thanks
Loading
Sam HobbsPosted Nov 20, 2011, 6:30 PM
Also note that you are checking for a letter using "if (chars[i] < 'a' || chars[i] > 'z')". Think about that; what will happen for upper case?
The output is not being formatted in a way that can be read easily, but if you take care of the above then I think you will at least have useful data.
Mike PatelPosted Nov 20, 2011, 5:23 PM
VulpesPosted Nov 20, 2011, 5:25 AM
To be able to answer this question, you need to be familiar with the String.Replace and String.ToUpper methods.
Concatenating strings can be done with the '+' operator e.g. "a" + "b" gives "ab"
You can iterate through a string using its indexer:
for(int i = 0; i < str.Length; i++)
{
char c = str[i]; // gets the 'i'th character of 'str' - starting from an index of zero
// do something with 'c' such as count its occurrences
}
You can also iterate using foreach:
foreach(char c in str)
{
// so something with 'c'
}
Sam HobbsPosted Nov 20, 2011, 3:22 AM
How much have you done? What specifically do you need help with? Since the question says nothing about that and instead it just describes what the assignment is, the implication is that you want someone to do everything for you. If someone did do it all for you then that would not help you learn though.