A regular string that gets a specific identity,
Pending string: #applyCom # the "#applyType #" item with the number "#applyNo #" has been requested for settles confirmation. Please log in to the system in time to view processing.
The #* #的形式作为占位符 is used here to identify the place to be processed.
Use regular processing code:
String content = "#applyCom # has requested settles confirmation for the" #applyType # "item with the number" #applyNo # ". Please log in to the system in time to view processing. "; Assemble the data that needs to be replaced, replace the placeholder hashmap<string with the values inside the map, string> map = new hashmap<string, string> (); Map.put ("applycom", "a"); Map.put ("Applytype", "B"); Map.put ("Applyno", "C"); Pattern Pat = Pattern.compile ("(#[^#]*#)");//define regular Matcher mat = pat.matcher (content); int i = 0; while (Mat.find ()) {//If there is a match String temp = mat.group (1). ToString (). substring (1, mat.group (1). ToString (). Length ()-1);// Get placeholders, such as: #applyCom # will get applycom content = Content.replace (Mat.group (1), Map.get (temp)),//Get the value from the map, and replace the placeholder i++; } System.out.println (content);//Print final string
To get a string for a particular identity and replace it with a regular type