我從 firebase 數據庫獲取密鑰如下: promoCodeKey = history.getKey();它給我輸出為 T20 Test10 等字符串我想將其保存在一個數組中,以便從 editText 檢查用戶是否輸入任何文本以及該文本是否與任何鍵匹配我怎樣才能做到這一點?我想從每個鍵進行檢查。
1 回答

白衣染霜花
TA貢獻1796條經驗 獲得超10個贊
您可以使用字符串拆分功能。
String keysString = history.getKey();
//removes all "Key promo is" text
String replaceString=keysString.replace("Key promo is","");
// removes all white spaces
String trimString = replaceString.replaceAll("\\s+","");
String[] keys = trimString.split(".");
for (int i = 0; i < keys.lenght; i++) {
if (keys[i] == editText.getText()) {
return true;
}
}
添加回答
舉報
0/150
提交
取消