简体   繁体   English

是否可以检查任何输入,如果它与 if 条件中的字符串类型匹配以执行一堆代码?

[英]Is it possible to check any input, if it is matched with String Type in if condition to execue bunch of codes?

Mainly I was working with a code.主要是我在使用代码。 where I am trying to get an input from a user in String type to execute some actions.我试图从字符串类型的用户那里获取输入以执行一些操作。 If the user don't input any type of value it will give another message to him.如果用户不输入任何类型的值,它将给他另一条消息。

I was finding if it is possible to check that input equal to any String type!我正在寻找是否可以检查输入是否等于任何 String 类型! I was trying this!我正在尝试这个!

    if (!(edt.getText().toString().equals("null"))) {

        txt.setText("Hello"+edt.getText().toString());
    }else{
        txt.setText("Wrong input");
    }

Maybe:也许:

    txt.setText(getResponse(edt.getText().toString()));

// ...

private getResponse(String input) {
    if (input == null || input.isEmpty()) {
        return String.format("Hello %s", input);
    } else {
        return "Wrong input";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM