-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added GetArgs #663
base: main
Are you sure you want to change the base?
Added GetArgs #663
Conversation
schwarper
commented
Nov 7, 2024
I improved this a bit. |
I'd also like the enumerator version maybe? from #504 |
I thought that getting arg once and split them is better than using GetArg multiple times. However, it might be better. |
Perhaps a solution like this would be the way forward, as I can see calling getarg multiple times might not be the best way forward (my solution), but nor do I think creating a list and a regex expression is (your solution). // Emulation of argstring
private static string ArgString = "my test string";
// Emulation of ArgCount
private static int ArgCount = ArgString.Split().Length;
static void Main(string[] args)
{
Console.WriteLine(string.Join(" ", TestMethods(2))); // Output: string
Console.WriteLine(string.Join(" ", TestMethods(1))); // output: test string
Console.WriteLine(string.Join(" ", TestMethods(1, 2))); // Output: test
Console.WriteLine(string.Join(" ", TestMethods(0, 1))); // Output: my
Console.WriteLine(string.Join(" ", TestMethods())); // Output: test string
}
private static IEnumerable<string> TestMethods(int startIndex = 1, int endIndex = -1)
{
endIndex = (endIndex > ArgCount || endIndex < 0) ? ArgCount : endIndex;
startIndex = (startIndex > ArgCount || startIndex < 0 || startIndex > endIndex) ? ArgCount : startIndex;
Console.WriteLine($"Start: {startIndex} | end: {endIndex}");
return ArgString.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).AsEnumerable().Skip(startIndex).Take(endIndex - startIndex);
} Splitting with Glad to see that a PR I made back in June and forgot all about is something that other people (you at least) would have the benefit of 😅 |