read lines from textfile and treat them as Main(args)

K

Ken Snyder

hi ng,

reading a file line by line is no big match, but
i would like to read them and convert them to
string[] as if they where given like command
line args so that i can preprocess them and hand
them over to my real main. how can i do that?
I will write the command line args into a file and
read them from there as if they were given from
the command line. can you give me a short example
please?

thanks in advance

cheers
ken
 
A

Arne Vajhøj

Ken said:
reading a file line by line is no big match, but
i would like to read them and convert them to
string[] as if they where given like command
line args so that i can preprocess them and hand
them over to my real main. how can i do that?
I will write the command line args into a file and
read them from there as if they were given from
the command line. can you give me a short example
please?

Use File.ReadAllLines !

Arne
 
K

Ken Snyder

hi arne,

what i meant was somthing like this:

file lines:

-p 123 -k 45 -h78
-k 54 -p 123 -a 45

the read each line with streamreader.readline
and then convert the read line string into string[]
like the applications args. i would like to pass the
read line to the app main args.


cheers
ken
 
A

Arne Vajhøj

Ken said:
what i meant was somthing like this:

file lines:

-p 123 -k 45 -h78
-k 54 -p 123 -a 45

the read each line with streamreader.readline
and then convert the read line string into string[]
like the applications args. i would like to pass the
read line to the app main args.

File.ReadAllLines(fnm) will return:
{ "-p 123 -k 45 -h78", "-k 54 -p 123 -a 45" }

File.ReadAllText(fnm).Split(" \r\n".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries)
will return:
{ "-p", "123", "-k", "45", "-h78", "-k", "54", "-p", "123", "-a", "45" }

You pick what you want.

Arne
 
K

Ken Snyder

hey, thats cool! thanks

cheers
ken


Arne Vajhøj said:
Ken said:
what i meant was somthing like this:

file lines:

-p 123 -k 45 -h78
-k 54 -p 123 -a 45

the read each line with streamreader.readline
and then convert the read line string into string[]
like the applications args. i would like to pass the
read line to the app main args.

File.ReadAllLines(fnm) will return:
{ "-p 123 -k 45 -h78", "-k 54 -p 123 -a 45" }

File.ReadAllText(fnm).Split(" \r\n".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries)
will return:
{ "-p", "123", "-k", "45", "-h78", "-k", "54", "-p", "123", "-a", "45" }

You pick what you want.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top