views:

70

answers:

1

what are the characters used to separate command-line arguments (such as white space, \t)? How do you check whether a string contains a separator? for example: Check("abcd") is false and Check("ab cd") or Check("ab\tcd") is true

+1  A: 

C# by default splits your arguments on bases of white space so there shouldn't be a need to split your arguments.

But if you have to do it for some reason then

You can split you command line arguments using string.split(' ') and get the array of strings

so basically you will do something like this

bool Check(string argument)
{
    string[] arguments = argument.split(' ');
    if (arguments.Length > 1) // In your case if you are expecting 2 or more arguments
    {
        return true;
    }
    return false;
}
Ankit
But there are other separators than a white space, right?
Louis Rhys
C# by default uses whitespace as the separator. if you want to use some other separators then you can take the argument and split it using the separators that you would like to support. so if you want to separate it using '-' then u can use argument.split('-')
Ankit
I mean, in command line if you pass "a\tb" a and b would become separated, right? I am asking what characters (other than whitespace) count as separators in command line
Louis Rhys
if you pass "a\tb" from a console it will be treated as string characters instead of escape sequence. so the parameter that you will receive in your application will be "a\\tb".
Ankit
ok I mean "a<tab>b" with <tab> = a tab
Louis Rhys