Camel style, underline style, cross-turn

Source: Internet
Author: User

1 /**2 * Converts a camel-named string to an underscore capitalization method. An empty string is returned if the pre-converted camel-named string is empty. </br>3 * For example: Helloworld->hello_world4  * @paramName the camel-named string before the conversion5  * @returnA string named after the converted underscore capitalization6  */7  Public Staticstring Underscorename (string name) {8StringBuilder result =NewStringBuilder ();9     if(Name! =NULL&& name.length () > 0) {Ten         //process the first character into uppercase OneResult.append (name.substring (0, 1). toUpperCase ()); A         //Loop through the remaining characters -          for(inti = 1; I < name.length (); i++) { -String s = name.substring (i, i + 1); the             //underline before capital letters -             if(S.equals (S.touppercase ()) &&! Character.isdigit (S.charat (0))) { -Result.append ("_"); -             } +             //other characters go directly to uppercase - Result.append (S.touppercase ()); +         } A     } at     returnresult.tostring (); - } -   - /** - * Converts a string named by an underscore in uppercase to a camel-style. Returns an empty string if the string that is named before the underscore capitalization method is empty. </br> - * For example: Hello_world->helloworld in  * @paramname the string that is named before the underscore capitalization method -  * @returnconverted camel-named string to  */ +  Public Staticstring Camelname (string name) { -StringBuilder result =NewStringBuilder (); the     //Quick Check *     if(Name = =NULL||Name.isempty ()) { $         //no need to convertPanax Notoginseng         return""; -}Else if(!name.contains ("_")) { the         //does not contain underscores, lowercase only the first letter +         returnName.substring (0, 1). toLowerCase () + name.substring (1); A     } the     //split the original string with an underscore +String camels[] = Name.split ("_"); -      for(String camel:camels) { $         //skips the beginning, end of a line change, or double underline in the original string $         if(Camel.isempty ()) { -             Continue; -         } the         //handle Real hump fragments. -         if(result.length () = = 0) {Wuyi             //First Hump fragment, all letters lowercase the Result.append (Camel.tolowercase ()); -}Else { Wu             //Other hump fragments, capitalized in the first letter -Result.append (camel.substring (0, 1). toUpperCase ()); AboutResult.append (camel.substring (1). toLowerCase ()); $         } -     } -     returnresult.tostring (); -}

Camel style, underline style, cross-turn

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.