ddanbe
Industrious Poster
4,297 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 723
Skill Endorsements: 26
You have way too much code and adding a class is too complicated for what you are doing. If you're using Visual Studio, start over with a clean project, compile it before doing anything else and then think about the problem.
Think character-array and characters.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
If you want a quick and dirty solution, break your input into a character array and loop through it. For each character check if it isDigit(), if yes no change is required. Then check for the special characters you need to remove. Lastly check isUpper for the character. If false use toUpper, if true use toLower to convert them.
In some simple but ugly pseudo code:
if(isDigit){
add to output string
} else if(isSpecial) {
do not add to output string
} else if(isUpper) {
character.toLower()
add to output string
} else {
character.toUpper()
add to output string
}
hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9
Inside your ChangeCase method, I would convert the string to a CharArray then iterate over each character and evaluate (with the isDigit(), isLower(), etc).
If you can use a StringBuilder, please do. Use the Append method to piece together the characters you can keep. ...and return the StgringBuilder as a string.
Please let me know if this is not clear.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Inside your ChangeCase method, I would convert the string to a CharArray
There is no need to do this. You can treat a String as if it was already a character array.
using System;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
String test = "this is a test string";
foreach (char c in test) {
Console.Write("{0}-", c);
}
Console.WriteLine();
for (int i = 0; i < test.Length; i++) {
Console.Write("{0}-", test[i]);
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Momerath
Senior Poster
3,729 posts since Aug 2010
Reputation Points: 1,322
Solved Threads: 624
Skill Endorsements: 13