Click here to Skip to main content
15,896,453 members
Home / Discussions / C#
   

C#

 
QuestionWarning Message box Pin
shahramkeyboard22-Feb-10 8:48
shahramkeyboard22-Feb-10 8:48 
AnswerRe: Warning Message box Pin
Not Active22-Feb-10 11:54
mentorNot Active22-Feb-10 11:54 
QuestionC# .net.Mail Pin
Jamelon6922-Feb-10 8:19
Jamelon6922-Feb-10 8:19 
AnswerRe: C# .net.Mail Pin
DaveyM6922-Feb-10 8:29
professionalDaveyM6922-Feb-10 8:29 
AnswerRe: C# .net.Mail Pin
Dr.Walt Fair, PE22-Feb-10 8:31
professionalDr.Walt Fair, PE22-Feb-10 8:31 
AnswerRe: C# .net.Mail Pin
Gaurav Dudeja India22-Feb-10 19:20
Gaurav Dudeja India22-Feb-10 19:20 
AnswerRe: C# .net.Mail Pin
Richard MacCutchan22-Feb-10 22:16
mveRichard MacCutchan22-Feb-10 22:16 
QuestionBest way to read ASCII input [modified] Pin
spainchaud22-Feb-10 6:13
spainchaud22-Feb-10 6:13 
I am porting a Fortran numerical modeling code (console application) to C#. I am new to C#, so I mostly convert Fortran subroutines into C# class methods. My code reads ASCII input to obtain the modeling parameters. The basic method I use to read the input has not changed in 12 years, and I always felt that there should be a better way to do it. Now that I am moving to a new language, would be a good time to learn that better way. In my reading I have seen references to parse trees and other concepts I am not familiar with. I would like to get a few suggestions or references to articles or books that might help me.

Below I show example of my input and code. The basic idea is to read a file line by line, breaking the line into tokens. those tokens are in string[] input. The read method in my InputData class looks for keywords, instantiating objects as appropriate. Each object has its own Read method. Each class with a Read method inherits from the Reader class.

This is a simplified input file. I will probably consider moving to XML input in the future, but right now I have to support this format.


FORMATION
    UNITS METERS
    TOP   1055
END


Simplified code:

public class Reader
{
    protected string readMode = "0";
    public virtual void Read(string[] input) { }
}


public class InputData : Reader
{
    public Formation formation;

    public override void Read(string[] input)
    {
        if (input.Length == 0) return;

        string firstword = input[0];
        if (firstword.CompareTo("FORMATIOM") == 0)
        {
            formation = new Formation();
            readMode = "FORMATION";
        }
        else if (readMode == "FORMATION")
        {
            formation.Read(input);
        }
    }
 }

public class Formation : Reader
{

    protected string depthUnits;          // units used for depth measurements
    protected double topBoundaryDepth;

    public override void Read(string[] input)
    {
        string firstword = input[0];

        if (firstword.CompareTo("UNITS") == 0)
        {
            depthUnits = input[1];
            readMode = "0";
        }
        else if (firstword.CompareTo("TOP") == 0)
        {
            topBoundaryDepth = Convert.ToDouble(input[1]);
            readMode = "0";
        }
    }
}<div class="signature"><div class="modified">modified on Monday, February 22, 2010 2:19 PM</div></div>

AnswerRe: Best way to read ASCII input Pin
harold aptroot22-Feb-10 6:32
harold aptroot22-Feb-10 6:32 
GeneralRe: Best way to read ASCII input Pin
spainchaud22-Feb-10 6:38
spainchaud22-Feb-10 6:38 
AnswerRe: Best way to read ASCII input [modified] Pin
Saksida Bojan22-Feb-10 6:36
Saksida Bojan22-Feb-10 6:36 
GeneralRe: Best way to read ASCII input Pin
harold aptroot22-Feb-10 6:39
harold aptroot22-Feb-10 6:39 
AnswerRe: Best way to read ASCII input Pin
Dr.Walt Fair, PE22-Feb-10 7:03
professionalDr.Walt Fair, PE22-Feb-10 7:03 
GeneralRe: Best way to read ASCII input Pin
spainchaud22-Feb-10 8:48
spainchaud22-Feb-10 8:48 
GeneralRe: Best way to read ASCII input Pin
Dr.Walt Fair, PE22-Feb-10 9:23
professionalDr.Walt Fair, PE22-Feb-10 9:23 
GeneralRe: Best way to read ASCII input Pin
Scott Serl22-Feb-10 10:13
Scott Serl22-Feb-10 10:13 
QuestionReports Pin
muka6622-Feb-10 3:22
muka6622-Feb-10 3:22 
AnswerRe: Reports Pin
Not Active22-Feb-10 3:42
mentorNot Active22-Feb-10 3:42 
GeneralRe: Reports Pin
Anubhava Dimri22-Feb-10 18:18
Anubhava Dimri22-Feb-10 18:18 
QuestionDecrypting a text using Rijndael Pin
3bood.ghzawi22-Feb-10 2:52
3bood.ghzawi22-Feb-10 2:52 
QuestionDecrypting a text using Rijndael Pin
3bood.ghzawi22-Feb-10 2:51
3bood.ghzawi22-Feb-10 2:51 
AnswerRe: Decrypting a text using Rijndael Pin
Not Active22-Feb-10 3:13
mentorNot Active22-Feb-10 3:13 
AnswerRe: Decrypting a text using Rijndael Pin
Keith Barrow22-Feb-10 4:20
professionalKeith Barrow22-Feb-10 4:20 
AnswerRe: Decrypting a text using Rijndael Pin
Luc Pattyn22-Feb-10 4:51
sitebuilderLuc Pattyn22-Feb-10 4:51 
GeneralRe: Decrypting a text using Rijndael Pin
Keith Barrow22-Feb-10 5:03
professionalKeith Barrow22-Feb-10 5:03 

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.