Hello I am a newbiew to java.
I am trying to write an macroresolver I have string which is represneted as
String s = '{object.attribute}' --> result of the resolver should be 'attribute'
String prefix = '{object.'
String suffix = '}'
that was easy.
i also want to extend to use the same resolver to resolve the following
String s = 'attrName1=$attrValue1$;&attrName2=$attrValue2$;' --> result of the resolver should be attrName1=attrValue1;&attrName2=attrValue2;
String prefix = '$'
String suffix = '$'
i can have a greneralized prefix and suffix passed to the method but not sure what the logic should be.
public class StringMacro {
/**
* @param args
*/
public static void main(String args[]) {
String s = "{article.article_type}";
String prefix = "{article.";
String suffix = "}";
int prefixLength = prefix.length();
int suffixLength = suffix.length();
int startIndex = s.indexOf("{article.");
int prevEndIndex =startIndex+s.indexOf(suffix);
StringBuffer output = new StringBuffer();
while (startIndex != -1 ) {
output.append(s.substring(startIndex+prefixLength,prevEndIndex));
int endIndex = s.indexOf(suffix,startIndex);
if ( endIndex == -1 ) {
output.append(s.substring(startIndex));
break;
}
String macro = s.substring(startIndex+prefixLength,endIndex-1);
prevEndIndex = endIndex+suffixLength;
startIndex = s.indexOf(prefix, prevEndIndex);
}
System.out.println(">>>"+output);
}
}
Help Please!!!!!