我想在字符串中查找字符。如果找到該字符,則向char_counter添加一個字符。我怎樣才能實現這個?如何搜索Java中每個字符的字符串
實施例:
int char_counter = 0;
String password = "1234";
String search = "1234";
for(int i = 0; i < password.length() - 1; i++) {
for(int j = 0; j < search.length() - 1; j++) {
//This is just pseudo code since I don't know how to properly search a string
if(password[i] == search[j]) {
char_counter = char_counter + 1;
}
}
}
你想在字符串中找到一個字符的出現是嗎? –