What is the better approach to trim unprintable characters from a string
<p>I am reading data from xml. When I checked in eclipse console I found I am getting the whole data with some square boxes. <strong>Example</strong> If there is 123 in excel sheet i am getting 123 with some square boxes. I used <code>trim()</code> to avoid such things but didnot get success because trim() method trims only white spaces. But I found those characters have ASCII value -17, -20 .. <strong>I dont want to trim only white spaces I want to trim those square boxes also</strong></p>

<p><strong>So I have used the following method to trim those characters and I got success.</strong></p>

<p>What is the more appropriate way of trimming a string</p>

<p><strong>Trimming a string</strong></p>

<pre><code>String trimData(String accessNum){
        StringBuffer sb = new StringBuffer();
        try{
            if((accessNum != null) &amp;&amp; (accessNum.length()&gt;0)){
//              Log.i("Settings", accessNum+"Access Number length....."+accessNum.length());
                accessNum = accessNum.trim();
                byte[] b = accessNum.getBytes();
                for(int i=0; i&lt;b.length; i++){
                    System.out.println(i+"....."+b[i]);
                    if(b[i]&gt;0){
                        sb.append((char)(b[i]));
                    }
                }
//              Log.i("Settigs", accessNum+"Trimming....");
            }}catch(Exception ex){

            }
            return sb.toString();
    }
</code></pre>
