如何使用代码提取+93表单国家/地区名称

时间:2015-02-17 12:15:13

标签: java android

我想提取国家代码(+93)  例如:Afghanistan(+93)此处我只需要+93如何删除国家/地区名称和大括号

          final Bundle GetData = getIntent().getExtras();
    String rl = GetData.getString("countrycode");
    for (String country : rl) {

        StringTokenizer tokenizer = new StringTokenizer(country, "()");
        tokenizer.nextToken();
        String codeVal = tokenizer.nextToken();
        CountryCode = (EditText) findViewById(R.id.SpCountryCode);
        CountryCode.setText(codeVal);

    }

2 个答案:

答案 0 :(得分:2)

你可以轻松使用这样的东西;

  String s = "Afghanistan(+93)";
  int plusf = s.indexOf("(");
  int plusl = s.indexOf(")");
  String newString = s.substring(plusf+1, plusl);
  System.out.println(newString);

输出为:+93

对于你的清单试试这个;

        String[] rl = { "Afghanistan(+ff93)", "Afghanistan(+93)", "Afghanistan(+493)", "Afghanistan(+454593)" };

        for (String country : rl) {

            StringTokenizer tokenizer = new StringTokenizer(country , "()");
            tokenizer.nextToken();
            String codeVal = tokenizer.nextToken();
            System.out.println(codeVal);

        }

答案 1 :(得分:0)

'StringTokenizer tokenizer = new StringTokenizer(stringCode,“()”); tokenizer.nextToken(); String codeVal = tokenizer.nextToken(); “