Ollyver
Ollyver

Reputation: 367

(How) can you pass whitespace as a command line argument in C#?

Is it possible to pass whitespace to a C# program as a command line argument?

I am writing a script that parses a text document, and would like to allow users to specify their own separator, rather than hard-coding one.

However, if the separator is a space, then the program appears to discount it as an argument, whether surrounded by quote marks or not.

Upvotes: 1

Views: 2061

Answers (3)

Chad Dienhart
Chad Dienhart

Reputation: 5194

you can pass in quoted whitespace " " For example

FileParsing.exe arg1 " " arg3 "some other arg"

Upvotes: 1

Dangercrow
Dangercrow

Reputation: 145

This might help:

Escape command line arguments in c#

From what some other similar questions say, using Regex seems to be the way to go.

(Not really done much C# I'm afraid, but just saw this on the homepage)

Upvotes: 1

Chris
Chris

Reputation: 5514

Environment.CommandLine will give you the complete command line, including any whitespace. Although I think it would be tricky for your users to pass tabs or line breaks. I'd suggest having them pass the char code(s) for the separator(s) instead.

Upvotes: 1

Related Questions