Recently processed string:
This string is available:
Stringbuilder test_string = new stringbuilder (); <br/> test_string.append ("55 10 16 6a ");
If "10 10" is replaced with "10" and "10 16" is replaced with "16", the rest will remain unchanged.
Remove the spaces in test_string and use a loop. The Code is as follows:
Stringbuilder trs_string = new stringbuilder (); // assign a value to the intermediate variable trs_string <br/> trs_string = test_string; <br/> int II, curpos; <br/> curpos = 2; <br/> for (II = curpos; II <trs_string.length-2; II = II + 2) <br/>{< br/> string trs_temp = convert. tostring (trs_string); // convert stringbuilder to string <br/> string trs_compare = trs_temp.substring (II, 4); // take 2 bytes (4 characters ), used to compare <br/> If (trs_compare.equals ("1016") | trs_compare.equals ("1010 ")) // check whether transparent transmitted bytes exist <br/>{< br/> string remain_string = trs_temp.substring (II + 2, trs_string.length-II-2 ); // retrieve all bytes after transparent transmission <br/> trs_string.remove (II, trs_string.length-II); // Delete bytes after II <br/> trs_string.append (remain_string ); <br/> II + = 2; // skip one byte after 0x10 <br/>}< br/>}
Later I found that it would be much faster to remove spaces, just call the replace method. Then I thought of a problem where the string is like this:
"55 10 10 10 10 16 6a"
Ideally processed string:
"55 10 16 6a"
String. will the Replace () method Replace "10 10" with "10" and then combine this "10" with the next "10" into "10 10 ", the result is processed as follows:
"55 16 6a" has only one "16" Left, but fortunately this situation will not happen after testing, the replace method adds the pointer after "10 10" or "10 16 ".
Conclusion: If you think about algorithms for a long time, replace does not process spaces, but you still have to cultivate them. The algorithms are a bit like internal work!