code: public void trim() {
      	try
      	{
      	//cut white spaces from the head
  		while (len>0 && chars[pos] == ' ') {
  			pos++;
  			len--;
  		}
      	
          //cut from the end
          while (len>0 && (chars[pos + len - 1] == ' ' || chars[pos + len - 1] == '\n' || chars[pos + len - 1] == '\r')) {
              len--;
          }
      	}
      	catch(Exception e)
      	{
      		System.out.println("len:" + len + ",pos:" + pos);
      	}
      }
docs: Removes whitespace from the head and tail of the string.