Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: VGA output in C# Pin
evertqin18-Nov-08 17:02
evertqin18-Nov-08 17:02 
GeneralRe: VGA output in C# Pin
Dave Kreskowiak18-Nov-08 17:42
mveDave Kreskowiak18-Nov-08 17:42 
AnswerRe: VGA output in C# Pin
Christian Graus18-Nov-08 11:47
protectorChristian Graus18-Nov-08 11:47 
Questionregular expression cleanup! Pin
nesfrank18-Nov-08 9:14
nesfrank18-Nov-08 9:14 
AnswerRe: regular expression cleanup! Pin
sph3rex18-Nov-08 9:34
sph3rex18-Nov-08 9:34 
AnswerRe: regular expression cleanup! Pin
carbon_golem18-Nov-08 9:54
carbon_golem18-Nov-08 9:54 
AnswerRe: regular expression cleanup! Pin
Garth J Lancaster18-Nov-08 10:17
professionalGarth J Lancaster18-Nov-08 10:17 
AnswerRe: regular expression cleanup! [modified] Pin
Robert.C.Cartaino18-Nov-08 11:16
Robert.C.Cartaino18-Nov-08 11:16 
I think you should forget about regular expressions as a solution to your problem. You really should consider cleaning up and re-working your code first... at least for the learning experience. Learning how to do these types of manipulations is pretty important and, looking at your code, you're just not there, yet.

All those temp variables and creating new strings in the loops area really expensive. Learn how strings work. Learn what immutable means and what happens when you build strings repeatedly within a loop.

As a first step, start from the basics. Learn to traverse a string and manipulate it character by character (as you attempted above). Start with something like this:
private string CleanString(string dirtyString)
{
    StringBuilder cleanString = new StringBuilder();  // Learn what this does and why to use it
    foreach (char c in dirtyString)
    {
        // Note: C# strings are made up of 2-byte Unicode/UTF-16 characters, not ASCII characters.
        if ((c != '\u0009') || (c != '\u000B') ... etc. )
        {
            // if character is not dirty, add it to the new string
            cleanString.Append(c);
        }
    }
    return (cleanString.ToString());
}
Get that working, but then start using .NET's built in methods to improve your code.

Next, read about string.IndexOf(char) so you can search the entire string at once for a character. Rewrite your code and get that working.

Then, try creating an array of "dirty characters" so you can search for them all at once. Start by reading about this stuff:
char[] dirtyChars = new char[] { '\u0009', '\u000B', ... etc. };
int dirtyIndex = dirtyString.IndexOfAny(dirtyChars);
Then rewrite your code again and get it working.

Then read about regular expressions, if you're curious. Will regular expressions work better? Maybe marginally... that's a really small "maybe." Probably not enough to matter. More readable?... I doubt it.

Enjoy,

Robert C. Cartaino

modified on Wednesday, November 19, 2008 5:24 PM

QuestionDataset with 6 columns, how to display only 3 in a data grid? Pin
jeweladdict18-Nov-08 9:06
jeweladdict18-Nov-08 9:06 
AnswerRe: Dataset with 6 columns, how to display only 3 in a data grid? Pin
Wendelius18-Nov-08 9:39
mentorWendelius18-Nov-08 9:39 
AnswerRe: Dataset with 6 columns, how to display only 3 in a data grid? Pin
Priya Prk18-Nov-08 9:40
Priya Prk18-Nov-08 9:40 
GeneralRe: Dataset with 6 columns, how to display only 3 in a data grid? Pin
jeweladdict18-Nov-08 9:47
jeweladdict18-Nov-08 9:47 
Questionthoughts on localizing SQL exceptions? Pin
Member 232448318-Nov-08 8:46
Member 232448318-Nov-08 8:46 
AnswerRe: thoughts on localizing SQL exceptions? Pin
Wendelius18-Nov-08 9:17
mentorWendelius18-Nov-08 9:17 
GeneralRe: thoughts on localizing SQL exceptions? Pin
Member 232448318-Nov-08 9:39
Member 232448318-Nov-08 9:39 
GeneralRe: thoughts on localizing SQL exceptions? Pin
Wendelius18-Nov-08 9:47
mentorWendelius18-Nov-08 9:47 
GeneralRe: thoughts on localizing SQL exceptions? Pin
Member 232448318-Nov-08 10:15
Member 232448318-Nov-08 10:15 
GeneralRe: thoughts on localizing SQL exceptions? Pin
Wendelius18-Nov-08 10:34
mentorWendelius18-Nov-08 10:34 
QuestionSpecifying pointer address, or something like that... Pin
boberick218-Nov-08 8:08
boberick218-Nov-08 8:08 
AnswerRe: Specifying pointer address, or something like that... Pin
Dave Kreskowiak18-Nov-08 8:21
mveDave Kreskowiak18-Nov-08 8:21 
GeneralRe: Specifying pointer address, or something like that... Pin
boberick218-Nov-08 8:37
boberick218-Nov-08 8:37 
GeneralRe: Specifying pointer address, or something like that... Pin
Paul Conrad18-Nov-08 8:43
professionalPaul Conrad18-Nov-08 8:43 
QuestionWeakreference Pin
Seetha.R18-Nov-08 6:41
Seetha.R18-Nov-08 6:41 
AnswerRe: Weakreference [modified] Pin
Lutosław18-Nov-08 6:53
Lutosław18-Nov-08 6:53 
AnswerRe: Weakreference Pin
Guffa18-Nov-08 11:55
Guffa18-Nov-08 11:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.