/ Published in: Java

I made this because org.apache.commons.lang.StringUtils does not have this method. I used this because i was dealing with a legacy db where all fields were char. trailing spaces were a pita.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
{ if(data==null) return null; char[]arr=data.toCharArray(); char[] newArr=new char[1]; int pos=0; //worst algorithm ever. but works! for (int i = 0; i < arr.length; i++) { pos=(arr.length-1)-i; // System.out.println("pos["+pos+"] i["+i+"] ["+arr[pos]+"]"); if(arr[pos]!=' ') { newArr= new char[pos+1]; break; } } }
Comments
