⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parserutils.java

📁 html 解析处理代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
 	        StringBuffer output = new StringBuffer();        boolean charFound=false;        for (int index=0; index<input.length(); index++)        {                charFound=false;            for (int charsCount=0; charsCount<charsToBeRemoved.length(); charsCount++)                if (charsToBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (!((Character.isWhitespace(input.charAt(index))) || (Character.isSpaceChar(input.charAt(index))) || (charFound)))                output.append(input.charAt(index));        }        return output.toString();    }    /**     * Remove from the beginning and the end of the input string all the spaces and tabs like chars.     * Remove also the chars specified in the input variable charsToBeRemoved.     * <BR>The removal process removes only chars at the beginning and at the end of the string.     * <BR>For example if you call trimSpacesBeginEnd(&quot;&lt;DIV&gt;  +12.5 &lt;/DIV&gt;&quot;, &quot;&lt;>DIV/&quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (space chars and &lt;,&gt;,D,I,V,/ are chars that must be removed).     * <BR>For example if you call trimSpacesBeginEnd(&quot;&lt;DIV&gt;  Trim all spaces but not the ones inside the string &lt;/DIV&gt;&quot;, &quot;&lt;>DIV/&quot;),     * <BR>you obtain a string &quot;Trim all spaces but not the ones inside the string&quot; as output (all the spaces inside the string are preserved).     * @param input The string in input.     * @param charsToBeRemoved The chars to be removed.     * @return The string as output.    */    public static String trimSpacesBeginEnd (String input, String charsToBeRemoved)    { 	        String output = new String();        int begin=0;        int end=input.length()-1;        boolean charFound=false;        boolean ok=true;        for (int index=begin; (index<input.length()) && ok; index++)        {                            charFound=false;            for (int charsCount=0; charsCount<charsToBeRemoved.length(); charsCount++)                if (charsToBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (!( (Character.isWhitespace(input.charAt(index))) || (Character.isSpaceChar(input.charAt(index))) || (charFound) ))            {                begin=index;                ok=false;            }        }        ok=true;        for (int index=end; (index>=0) && ok; index--)        {            charFound=false;            for (int charsCount=0; charsCount<charsToBeRemoved.length(); charsCount++)                if (charsToBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (!( (Character.isWhitespace(input.charAt(index))) || (Character.isSpaceChar(input.charAt(index))) || (charFound) ))            {                end=index;                ok=false;            }        }        output=input.substring(begin,end+1);        return output;            }        /**     * Split the input string considering as string separator     * all the characters     * with the only exception of the characters specified in charsDoNotBeRemoved param.     * <BR>For example if you call splitButChars(&quot;&lt;DIV&gt;  +12.5, +3.4 &lt;/DIV&gt;&quot;, &quot;+.1234567890&quot;),     * <BR>you obtain an array of strings {&quot;+12.5&quot;, &quot;+3.4&quot;} as output (+,.,1,2,3,4,5,6,7,8,9,0 are chars that do not be removed).     * @param input The string in input.     * @param charsDoNotBeRemoved The chars that do not be removed.     * @return The array of strings as output.    */    public static String[] splitButChars (String input, String charsDoNotBeRemoved)    { 	        ArrayList output = new ArrayList();        int minCapacity = 0;        StringBuffer str = new StringBuffer();        boolean charFound = false;        boolean toBeAdd = false;        for (int index=0; index<input.length(); index++)        {                charFound=false;            for (int charsCount=0; charsCount<charsDoNotBeRemoved.length(); charsCount++)                if (charsDoNotBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (charFound)            {                str.append(input.charAt(index));                toBeAdd=false;            }            else                if (!toBeAdd)                    toBeAdd=true;            // finished to parse one string            if (toBeAdd && (str.length()!=0)) {                minCapacity++;                output.ensureCapacity(minCapacity);                if (output.add(str.toString()))                    str = new StringBuffer();                else                    minCapacity--;            }        }        // add the last string        if (str.length()!=0) {            minCapacity++;            output.ensureCapacity(minCapacity);            if (output.add(str.toString()))                str = new StringBuffer();            else                minCapacity--;        }        output.trimToSize();        Object[] outputObj = output.toArray();        String[] outputStr = new String[output.size()];        for (int i=0; i<output.size(); i++)            outputStr[i] = new String((String) outputObj[i]);        return outputStr;            }        /**     * Remove from the input string all the characters     * with the only exception of the characters specified in charsDoNotBeRemoved param.     * <BR>For example if you call trimButChars(&quot;&lt;DIV&gt;  +12.5 &lt;/DIV&gt;&quot;, &quot;+.1234567890&quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (+,.,1,2,3,4,5,6,7,8,9,0 are chars that do not be removed).     * <BR>For example if you call trimButChars(&quot;&lt;DIV&gt;  +1 2 . 5 &lt;/DIV&gt;&quot;, &quot;+.1234567890&quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (the spaces between 1 and 2, 2 and ., . and 5 are removed).     * @param input The string in input.     * @param charsDoNotBeRemoved The chars that do not be removed.     * @return The string as output.    */    public static String trimButChars (String input, String charsDoNotBeRemoved)    { 	        StringBuffer output = new StringBuffer();        boolean charFound=false;        for (int index=0; index<input.length(); index++)        {                charFound=false;            for (int charsCount=0; charsCount<charsDoNotBeRemoved.length(); charsCount++)                if (charsDoNotBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (charFound)                output.append(input.charAt(index));        }                return output.toString();            }        /**     * Remove from the beginning and the end of the input string all the characters     * with the only exception of the characters specified in charsDoNotBeRemoved param.     * <BR>The removal process removes only chars at the beginning and at the end of the string.     * <BR>For example if you call trimButCharsBeginEnd(&quot;&lt;DIV&gt;  +12.5 &lt;/DIV&gt;&quot;, &quot;+.1234567890&quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (+,.,1,2,3,4,5,6,7,8,9,0 are chars that do not be removed).     * <BR>For example if you call trimButCharsBeginEnd(&quot;&lt;DIV&gt;  +1 2 . 5 &lt;/DIV&gt;&quot;, &quot;+.1234567890&quot;),     * <BR>you obtain a string &quot;+1 2 . 5&quot; as output (the spaces inside the string are not removed).     * @param input The string in input.     * @param charsDoNotBeRemoved The chars that do not be removed.     * @return The string as output.    */    public static String trimButCharsBeginEnd (String input, String charsDoNotBeRemoved)    { 	        String output = new String();        int begin=0;        int end=input.length()-1;        boolean charFound=false;        boolean ok=true;        for (int index=begin; (index<input.length()) && ok; index++)        {                            charFound=false;            for (int charsCount=0; charsCount<charsDoNotBeRemoved.length(); charsCount++)                if (charsDoNotBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (charFound)            {                begin=index;                ok=false;            }        }        ok=true;        for (int index=end; (index>=0) && ok; index--)        {            charFound=false;            for (int charsCount=0; charsCount<charsDoNotBeRemoved.length(); charsCount++)                if (charsDoNotBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (charFound)            {                end=index;                ok=false;            }        }        output=input.substring(begin,end+1);        return output;            }    /**     * Split the input string considering as string separator     * the chars specified in the input variable charsToBeRemoved.     * <BR>For example if you call splitChars(&quot;&lt;DIV&gt;  +12.5, +3.4 &lt;/DIV&gt;&quot;, &quot; <>DIV/,&quot;),     * <BR>you obtain an array of strings {&quot;+12.5&quot;, &quot;+3.4&quot;} as output (space chars and &lt;,&gt;,D,I,V,/ and the comma are chars that must be removed).     * @param input The string in input.     * @param charsToBeRemoved The chars to be removed.     * @return The array of strings as output.    */    public static String[] splitChars (String input, String charsToBeRemoved)    { 	        ArrayList output = new ArrayList();        int minCapacity = 0;        StringBuffer str = new StringBuffer();        boolean charFound = false;        boolean toBeAdd = false;        for (int index=0; index<input.length(); index++)        {                charFound=false;            for (int charsCount=0; charsCount<charsToBeRemoved.length(); charsCount++)                if (charsToBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (!(charFound))            {                str.append(input.charAt(index));                toBeAdd=false;            }            else                if (!toBeAdd)                    toBeAdd=true;            // finished to parse one string            if (toBeAdd && (str.length()!=0)) {                minCapacity++;                output.ensureCapacity(minCapacity);                if (output.add(str.toString()))                    str = new StringBuffer();                else                    minCapacity--;            }        }        // add the last string        if (str.length()!=0) {            minCapacity++;            output.ensureCapacity(minCapacity);            if (output.add(str.toString()))                str = new StringBuffer();            else                minCapacity--;        }        output.trimToSize();        Object[] outputObj = output.toArray();        String[] outputStr = new String[output.size()];        for (int i=0; i<output.size(); i++)            outputStr[i] = new String((String) outputObj[i]);        return outputStr;            }    /**     * Remove from the input string all the chars specified in the input variable charsToBeRemoved.     * <BR>For example if you call trimChars(&quot;&lt;DIV&gt;  +12.5 &lt;/DIV&gt;&quot;, &quot;<>DIV/ &quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (&lt;,&gt;,D,I,V,/ and space char are chars that must be removed).     * <BR>For example if you call trimChars(&quot;&lt;DIV&gt;  Trim All Chars Also The Ones Inside The String &lt;/DIV&gt;&quot;, &quot;<>DIV/ &quot;),     * <BR>you obtain a string &quot;TrimAllCharsAlsoTheOnesInsideTheString&quot; as output (all the spaces inside the string are removed).     * @param input The string in input.     * @param charsToBeRemoved The chars to be removed.     * @return The string as output.    */    public static String trimChars (String input, String charsToBeRemoved)    { 	        StringBuffer output = new StringBuffer();        boolean charFound=false;        for (int index=0; index<input.length(); index++)        {                charFound=false;            for (int charsCount=0; charsCount<charsToBeRemoved.length(); charsCount++)                if (charsToBeRemoved.charAt(charsCount)==input.charAt(index))                    charFound=true;            if (!(charFound))                output.append(input.charAt(index));        }        return output.toString();    }    /**     * Remove from the beginning and the end of the input string all the chars specified in the input variable charsToBeRemoved.     * <BR>The removal process removes only chars at the beginning and at the end of the string.     * <BR>For example if you call trimCharsBeginEnd(&quot;&lt;DIV&gt;  +12.5 &lt;/DIV&gt;&quot;, &quot;<>DIV/ &quot;),     * <BR>you obtain a string &quot;+12.5&quot; as output (' ' is a space char and &lt;,&gt;,D,I,V,/ are chars that must be removed).     * <BR>For example if you call trimCharsBeginEnd(&quot;&lt;DIV&gt;  Trim all spaces but not the ones inside the string &lt;/DIV&gt;&quot;, &quot;<>DIV/ &quot;),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -