c# - Check if parameter is already chosen in console -


i'm writing flesch index calculator , want able start program console command , .exe itself. want read in .txt files in console command fleschindexcalc.exe -f "path of file" , able select calculation formula either english text parameter -e or german text -g.

when start console command: type in parameters myself.

when start .exe: program asks language , have write g ore , press enter.

now question: how can tell program while starting console chose language doesn't ask me again started .exe?

here's got:

(if need more code fleschscore.cs ask :) )

namespace flesch_reading_ease {     public class program     {         public static void main(string[] args)         {             string filename = string.empty;             string[] parameters = new string[] { "-f", "-g", "-e" };               console.writeline("flesch reading ease");             console.writeline("");               if (args.length == 0)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("error!");                 console.resetcolor();                 console.writeline("no file found!");                 console.writeline("");                 console.write("press key...");                 console.readkey();                 return;             }              foreach (string arg in args)             {                //------- write here? -------             }              filename = args[0];              fleschscore fs = new fleschscore(filename);             fs.run();         }     } } 

my method choose language looks this:

private void selectlanguage()         {                         {                 console.writeline("choose language:");                 console.writeline("- german(g)");                 console.writeline("- english(e)");                  string lang = console.readline();                 switch (lang.toupper())                 {                     case "d":                         _selectedlanguage = language.german;                         break;                      case "e":                         _selectedlanguage = language.english;                         break;                      default:                         _selectedlanguage = language.undefined;                         console.writeline("wrong input. enter viable letter.");                         console.writeline("");                         break;                 }             } while (_selectedlanguage == language.undefined);         } 

you loop through arguments , keep track of what's entered. after check if have info need , pass parameters whatever method/class needs it.

bool isgerman = false; bool isenglish = false; bool nextentryisfilename = false; string filename = null;  foreach (string arg in args) {     switch (arg)     {         case "-e":             isenglish = true;             nextentryisfilename = false;             break;         case "-g":             isgerman = true;             nextentryisfilename = false;             break;         case "-f":             nextentryisfilename = true;             break;         default:             if (nextentryisfilename)             {                 filename = arg;                 nextentryisfilename = false;             }             break;     } }  if (!(isenglish ^ isgerman)) {     // select language }  if (string.isnullorempty(filename)) {     // ask filename }  var language = ...  fleschscore fs = new fleschscore(language, filename); fs.run(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -