Android 获取引号字符之间的字符串

Android 获取引号字符之间的字符串,android,substring,Android,Substring,我有一根像 "/d/WdTkRcxA/" + (446767 % 51245 + 446767 % 913) + "/Test%20vol.zip" 我需要“字符和()字符之间的值 /d/WdTkRcxA/ 446767 % 51245 + 446767 % 913 /Test%20vol.zip 我知道如何使用 String result = result.substring(result.indexOf("(") + 1, result.indexOf(")")); 但是我在获取/d

我有一根像

"/d/WdTkRcxA/" + (446767 % 51245 + 446767 % 913) + "/Test%20vol.zip"
我需要
字符和
字符之间的值

/d/WdTkRcxA/
446767 % 51245 + 446767 % 913
/Test%20vol.zip
我知道如何使用

String result = result.substring(result.indexOf("(")  + 1, result.indexOf(")"));
但是我在获取/d/WdTkRcxA//Test%20vol.zip时遇到困难


有人能提供建议吗?

在这种情况下,子字符串变得有点太复杂,所以最好使用正则表达式。使用这种模式:
[”([)([^\)“]*)[”]
,您可以从该文本中提取目标字符串:

String text = "\"/d/WdTkRcxA/\" + (446767 % 51245 + 446767 % 913) + \"/Test%20vol.zip\"";
Pattern pattern = Pattern.compile("[\"(]([^\\)\"]*)[\")]");

Matcher m = pattern.matcher(text);
while (m.find()) {
    String value = m.group(1);

    System.out.println(value);
}
结果:

/d/WdTkRcxA/
446767 % 51245 + 446767 % 913
/Test%20vol.zip

嗨,雅各布,谢谢。我需要将值/d/WdTkRcxA/和/Test%20vol.zip分配给一个单独的字符串。val1=/d/WdTkRcxA/val2=/Test%20vol.zip您的代码也可以这样做,它似乎可以工作,但第一个值(/d/WdTkRcxA/)丢失。@Simon在
while
循环之前定义一个
数组列表
,并将每个
值添加到其中以代替
System.out.println
行如何?是的。