/**
*
* 查找所有的变量
*
* @param str
* @return String
*/
private String[] findVariable(String str) {
StringBuffer temp = new StringBuffer("");
int beginIndex = str.indexOf(FLAG_START);
int endIndex = str.indexOf(FLAG_END);
while(beginIndex != -1 && endIndex != -1) {
temp.append(str.substring(beginIndex + 2, endIndex));
str = str.substring(endIndex+1);
beginIndex = str.indexOf(FLAG_START);
endIndex = str.indexOf(FLAG_END);
if(beginIndex != -1 && endIndex !=-1 ) {
temp.append(",");
}
}
if(!temp.toString().equals("")) {
return temp.toString().split(",");
}
return null;
}
*
* 查找所有的变量
*
* @param str
* @return String
*/
private String[] findVariable(String str) {
StringBuffer temp = new StringBuffer("");
int beginIndex = str.indexOf(FLAG_START);
int endIndex = str.indexOf(FLAG_END);
while(beginIndex != -1 && endIndex != -1) {
temp.append(str.substring(beginIndex + 2, endIndex));
str = str.substring(endIndex+1);
beginIndex = str.indexOf(FLAG_START);
endIndex = str.indexOf(FLAG_END);
if(beginIndex != -1 && endIndex !=-1 ) {
temp.append(",");
}
}
if(!temp.toString().equals("")) {
return temp.toString().split(",");
}
return null;
}
本文介绍了一种在字符串中查找并提取所有变量的方法。通过使用特定的开始和结束标记来定位变量的位置,并将它们逐一提取出来。该方法适用于处理配置文件或模板语言中的变量替换任务。
192

被折叠的 条评论
为什么被折叠?



