我正在为Minecraft进行基于命令的修改,允许你使用标志( - [az])来指定某些值。 但是,我对如何解析常规参数感到有些困惑。 这是一个命令的例子: /tp fist -h 。 当然,它对于字符串[0]等于相对简单,但如果我尝试/tp -h fist ,我恐怕我会混淆修改并且它会引发异常。
所以,我的问题是:是否有可能创建一个String []从现有列表中删除特定类型的字符串,所以我可以做if(args[0].equalsIgnoreCase("text") ,它会做同样的事情for /command text [text-to-remove]好像我做了/command [text-to-remove] text ?
提前致谢!
此致
afistofirony
PS:我知道我可以使用for循环来检查每个单独的参数,但通常变量会在每次执行时发生变化(因为它们通常用于指定并非全部共享名称的玩家)。
I'm working on a command-based modification for Minecraft in which you are allowed to use flags (-[a-z]) to specify certain values. However, I'm slightly confused on how I should go about parsing regular arguments. Here's an example of a command: /tp fist -h. Of course, it's relatively simple to what string[0] equals, but if I were to try /tp -h fist, I'm afraid I would confuse the modification and it would throw an exception.
So, my question is: is it possible to create a String[ ] which removes a specific type of string from an existing list so I can do if(args[0].equalsIgnoreCase("text") and it would do the same thing for /command text [text-to-remove] as if I did /command [text-to-remove] text?
Thanks in advance!
Sincerely,
afistofirony
PS: I know I can use a for loop to check each individual argument, but normally the variables will change for each execution (since they are usually used to specify players that don't all share a name).
最满意答案
最简洁的答案是不。 您必须重新创建原始的子集数组或跟踪忽略的索引。
很长的答案是你可以创建自己的集合来执行这种隐式过滤。
在像Scala过滤的FP语言中,集合更容易。 Java你通常必须遍历集合。
The short answer is no. You will have to either recreate a subset array of the original or keep track of the ignored indexes.
The long answer is that you could create your own collection that does this implicit filtering.
In a FP language like scala filtering a collection is much easier. Java you will have to usually loop through the collection.
更多推荐
发布评论