best way of replacing all tags in a string with java -


I have a service method that takes the string and then replaces the tag in the string with the item from the tag library. As follows:

 for  (MetaDataDTO tag: tagValues) {message = message.replace (tag.getKey (), tag getText1 ()); }  

Obviously; They make piles of new strings and have BAD. But StringBuilder is harder to use the method to use for multiple strings inside a string. How can I make my way more efficient?

This is for use with blocks of text:

Dear # First Name #, # Application Type # Your application for # has been approved # Sorry.

Whereas # firstname #, etc. are the keys to the meta data database. It is also possible that the tag hashes are not surrounded by characters. Actually you want to copy execution like this:

 

public stable string replacement tag (string message, map & lt; string, string & gt; tag) {patterns p = pattern.compile ("# (\\ w +) #"); Matter M = P. Mitcher (message); Boolean results = m.find (); If (result) {stringbuffer sb = new stringbuffer (); Do {m.appendReplacement (sb, tags.containsKey (m.group (1)? Tags.get (m.group (1)): ""); result = m.find ();} while (result); m .appendTail (sb); Message = sb.toString ();} Return message;}

Note: I have created an impression about a valid tag ( (I.e. "# ([\ w _] +) #").

I have also considered the tag above that looks something like:

map & Lt; string, string & gt; tag = new hashmop & lt; string, string & gt; (); tags.add ("firstname", "Skippy");

and No:

  tag.add ("# ago name #", "Skippy");  

If the second is correct, you will need to adjust accordingly.

This method passes only one string in the message string, so it is not more efficient than this Get it.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -