private String encodeVal(String v){
  char[] chars=v.toCharArray();
  StringBuilder sb=new StringBuilder(chars.length + 20);
  int i=0, lastIdx=0;
  for (i=0; i < chars.length; i++) {
    if (chars[i] == '%') {
      if (lastIdx != i) {
        sb.append(chars,lastIdx,i - lastIdx);
      }
      sb.append("%25");
      lastIdx=i + 1;
    }
 else     if (chars[i] == ',') {
      if (lastIdx != i) {
        sb.append(chars,lastIdx,i - lastIdx);
      }
      sb.append("%2C");
      lastIdx=i + 1;
    }
  }
  if (lastIdx != i) {
    sb.append(chars,lastIdx,i - lastIdx);
  }
  return sb.toString();
}

private String encodeVal ( String v ) { char [ ] chars = v . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( chars . length + 20 ) ; int i = 0 , lastIdx = 0 ; for ( i = 0 ; i < chars . length ; i ++ ) { if ( chars [ i ] == '%' ) { if ( lastIdx != i ) { sb . append ( chars , lastIdx , i - lastIdx ) ; } sb . append ( "%25" ) ; lastIdx = i + 1 ; } else if ( chars [ i ] == ',' ) { if ( lastIdx != i ) { sb . append ( chars , lastIdx , i - lastIdx ) ; } sb . append ( "%2C" ) ; lastIdx = i + 1 ; } } if ( lastIdx != i ) { sb . append ( chars , lastIdx , i - lastIdx ) ; } return sb . toString ( ) ; }
encodes special characters in a value . percent to % 25 and comma to % 2c .
