我正在製作一個TeamSpeak3 ServerQuery bot,命令行樣式。我已經下了命令,但是我似乎無法將我的頭包裹起來,這是命令的參數。我使用reset()方法創建參數列表,因此組合字符串會更容易。結合使用雙引號的參數
例如,假設我改變內存設置爲我的機器人的名字
set query name "Kyles Bot"
但該方案以「Kyles和機器人」作爲兩個不同的參數。我希望他們是一個整體。我會如何去做這件事?復位所需
字段():
// Keep String[] and 3 strings null for now, they'll be changed.
private String command, to1, to2;
private String[] to3;
private List<String> args = new ArrayList<>();
復位()方法:
private void reset() {
args.clear();
to1 = line.getText();
command = to1.split(" ")[0];
if (to1.split(" ").length > 1) {
to2 = to1.substring(command.length() + 1, to1.length());
to3 = to2.split(" ");
for (int i = 0; i < to3.length; i++) {
if (to3[i].isEmpty() || to3[i].startsWith(" ")) {
System.out.println("Argument null, command cancelled. [" + to3[i] + "]");
break;
} else {
args.add(to3[i]);
}
}
//EDIT2: Removed useless for loop,
//it was my previous attempt to solve the problem.
} else {
//EDIT: This loop here is used to prevent AIOUB
command = to1;
for (int i = 0; i < 5; i++) {
args.add("NullElement");
}
}
}
'設置查詢名稱「Kyles Bot」'這看起來很可疑。你是否得到一個環境變量?他們不能包含空格。嘗試'設置查詢名稱「Kyles Bot」' – Michael
否@Michael,這些命令與我在另一個類中使用的HashMap進行交互。對不起,如果不明確。如果您願意,我會在課堂上發佈該課程。 – FlashDaggerX
這已經是相當長的代碼示例,所以不要這樣做。我懷疑你的大部分代碼與這個特定的問題沒有關係。請創建一個[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve) - 基本刪除*不相關的所有*,並確保您發佈的代碼能夠在其上運行如果我們將其複製並粘貼到IDE,那麼它就是自己的。如果你這樣做,我會確保要麼解決你的問題,要麼提高獎金,這樣別人就會。 – Michael