Topic:
Two functions encode () and decode () are implemented in the Java language, respectively, to transform and restore the string. The transform function encode () sequentially examines the characters of a known string, generating a new string in groups, grouped by the following rules:
(1) If the current character of the string is known to be not a numeric character greater than 0, the character is copied in the new string;
(2) If the current character of the string is known to be a numeric character, and there is no subsequent character after it, simply copy it to the new string;
(3) If the current character of the string is known to be a numeric character greater than 0, and there are subsequent characters, set the value of the numeric character is N, then its successor character (including the subsequent character is a numeric character) is duplicated n+1 times to the new string;
(4) In a group of the above transformations, insert an underscore ' _ ' between different groups for separation;
(5) If the string is known to contain an underscore ' _ ', the transformation is "\ul".
Code Run Results
JAVA string topic implementation of encode () and decode () calls with static methods