JAVA string topic implementation of encode () and decode () calls with static methods

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.