Java script: Remove the empty string value

Source: Internet
Author: User

    /**     *  @title   Remove null values in the string ', ' as a delimiter       *          gets the individual fields from the database when its value is ', ' * * *, ' * *, ', '   "," * * * "' when,     *          This method can be used to remove the first delimiter and the empty part of the data,     *           The string into the normal data string '   ' * * * *, ' * * * ', ' * * * '   '      *  @param   STR: string to convert      *  @return      */     public string strchange (STRING STR) {         Return strchange (str,null);     }        /**      *  @title   Remove null values in a string      *           the individual fields obtained from the database, when their valuesFor ', ' * * * ', ' * * * ', '   ', ' * * * ' when,     *           can use this method to remove the first delimiter and the empty part of the data,     *           the string into the normal data string '   ' * * * *, ' * * * ', ' * * * '   '      *  @param  STR: String to convert      *  @param  split :  delimiter (default = ', ')       *  @return      */    public string  strchange (string str,string split) {        //1, If the separator is empty, the default is ', '         if (split.trim () = = ""  | |  split == null) {            split= " , ";         }        //2, Convert a string to an array         sTring[] arr=str.split (split);         //3, defining intermediate variables value         string value= "";         //4, Iterates through the array, adding it to value if the subscript index corresponds to a value of null or an empty string         for  (string  S : arr)  {            // Note: If the string is judged to be empty, be sure to trim () because: "    " .length != 0             if (S!=null && s.trim (). IsEmpty ())                  value+=s+split;         }        //5, if value is empty, Returns null, not empty, then the last character of value is removed and then returned to         return value==null?null: Value.substring (0, value.length ()-1);    } 


This article is from the "9891958" blog, please be sure to keep this source http://9901958.blog.51cto.com/9891958/1662427

Java script: Remove the empty string value

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.