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
views:
70answers:
1
+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
2010-09-08 04:15:58
But there are other separators than a white space, right?
Louis Rhys
2010-09-08 04:17:17
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
2010-09-08 04:25:31
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
2010-09-08 04:34:47
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
2010-09-09 05:00:40
ok I mean "a<tab>b" with <tab> = a tab
Louis Rhys
2010-09-09 07:06:15