string - java macroresolver -


Hello I am a new interview for Java.

I am trying to write a macrosolver, I have a string that is represneted as

  string s = '{object.attribute}' - & gt; Resolver's result should be 'attribute' string prefix = '{object.' String suffix = '}'  

It was easy.

I also want to extend the same resolver to solve the following:

  string s = 'attrName1 = $ attrValue1 $; & AttrName2 = $ attrValue2 $; ' - & gt; Resolver result attrName1 = attrValue1; & AttrName2 = attrValue2; String prefix = '$' string suffix = '$'  

I have a granularized prefix and suffix with the method but not sure what the argument should be.

  public square string manga {/ ** * @ ultimate args * / public static zero major (string agr []) {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.sstring (startIndex + prefixLength, prevEndIndex)); Int endIndex = s.indexOf (suffix, startIndex); If (endIndex == -1) {output.append (s.sstring (startIndex)); break; } String macro = s.sstring (startIndex + prefixLength, endIndex-1); PrevEndIndex = ENDEX + Accuracy; StartIndex = s.indexOf (prefix, prevEndIndex); } System.out.println (">>>" + Output "); }  

}

Support please !!!!!

This should probably do the trick. Public Static Zero Main (String AGR []) {String S = "attribute 1 = $ attribute 1 value end and $ att 2 = $ attr2Value $ test" string; String prefix = "$"; String suffix = "$"; String s1 = "{obj.attr}"; String prefix 1 = "{obj"; String suffix 1 = "}"; Int prefixIndex = 0; Int startIndex = 0; Int endIndex = 0; Map map = new hashmap (); Map.put ("attr1Value", "100W"); Map.put ("attr2Value", "123W"); Map.put ("attr", "columnist"); String buffer buffer = new stringbuffer (); While (prefixIndex! = -1) {prefixIndex = s.indexOf (prefix, prefix index); EndIndex = s.indexOf (suffix, prefix index + prefix.length ()); Buffer.Append (S.SubString (Start Import, Prefix Index)); If (endIndex == -1) {break; } System.out.println (s.sstring (prefixIndex + prefix.length (), and index)); Buffer.app (map.gate (ssbstring (prefix index + prefix.lamp (), and index))); PrefixIndex = s.indexOf (prefix, endexx + suffix.length ()); StartIndex = endIndex + suffix.length (); } If (prefixIndex == -1) {buffer.epend (ss.bustring (endindex + suffix.lumber (());} System.out.println (buffer);}

}


Comments