我正在尝试在字符串到达并满足某些条件时对其进行格式化。但是,如果下面的标记长度不同,事情不匹配,我该怎么做?我希望所有“IP 地址”都匹配。我假设我使用类似 %20s 的东西?
if (tokens.length == 4 && (tokens[3].equals("up") || tokens[3].equals("down"))){
String result = String.format("%s is %s. IP address: %s \n", tokens[0], tokens[2], tokens[1]);
final String ReceivedText = mReceiveBox.getText().toString() + result;
if(tokens[2].equals("up")){
runOnUiThread(new Runnable() {
public void run() {
mReceiveBox.setText(ReceivedText);
mReceiveBox.setSelection(ReceivedText.length());
}
});
}
}