Java StringBuilder.deleteCharAt Examples

Java StringBuilder.deleteCharAt - 30 examples found. These are the top rated real world Java examples of StringBuilder.deleteCharAt extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  private static String fourDigits2Chinese(String digit) {

    int value = Integer.parseInt(digit);
    boolean hasZero = false;

    StringBuilder chineseDigit = new StringBuilder();

    int exponent = 3;
    for (; exponent >= 0; exponent--) {

      int divisor = (int) Math.pow(10, exponent);
      int result = value / divisor;
      if (result != 0) {
        chineseDigit.append(TOBIG[result]);
        chineseDigit.append(FOUR_DIGIT_UNIT[exponent]);
        hasZero = false;
      } else if (result == 0 && !hasZero) {
        chineseDigit.append(TOBIG[0]);
        hasZero = true;
      }
      value %= divisor;
    }

    // Delete redundant zero at head
    if (chineseDigit.toString().startsWith("零")) {
      chineseDigit.deleteCharAt(0);
    }

    // Delete redundant zero at tail
    if (chineseDigit.toString().endsWith("零")) {
      return chineseDigit.deleteCharAt(chineseDigit.length() - 1).toString();
    } else {
      return chineseDigit.toString();
    }
  }
Example #2
0
  private void addUsernameCookie(
      String username,
      String firstname,
      String lastname,
      HttpServletRequest request,
      HttpServletResponse response) {
    StringBuilder un = new StringBuilder(new String(Base64.encodeBase64(username.getBytes())));
    while (un.charAt(un.length() - 1) == '=') {
      un.deleteCharAt(un.length() - 1);
    }
    response.addCookie(createCookie(USERNAME, un.toString(), request));

    StringBuilder fn = new StringBuilder();
    if (!StringUtils.isBlank(firstname)) {
      fn.append(firstname);
    }
    fn.append(":");
    if (!StringUtils.isBlank(lastname)) {
      fn.append(lastname);
    }
    String value = fn.toString();
    fn = new StringBuilder(new String(Base64.encodeBase64(value.getBytes())));
    while (fn.charAt(fn.length() - 1) == '=') {
      fn.deleteCharAt(fn.length() - 1);
    }
    Cookie c = createCookie(FULLNAME, fn.toString(), request);
    c.setMaxAge(Integer.MAX_VALUE);
    response.addCookie(c);
  }
Example #3
0
  // build query
  @Override
  protected String buildQueryUrl(RequestParams params) {
    String uri = params.getUri();
    StringBuilder queryBuilder = new StringBuilder(uri);
    if (!uri.contains("?")) {
      queryBuilder.append("?");
    } else if (!uri.endsWith("?")) {
      queryBuilder.append("&");
    }
    HashMap<String, String> queryParams = params.getQueryStringParams();
    if (queryParams != null) {
      for (Map.Entry<String, String> entry : queryParams.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) {
          queryBuilder.append(Uri.encode(name)).append("=").append(Uri.encode(value)).append("&");
        }
      }
      if (queryBuilder.charAt(queryBuilder.length() - 1) == '&') {
        queryBuilder.deleteCharAt(queryBuilder.length() - 1);
      }
    }

    if (queryBuilder.charAt(queryBuilder.length() - 1) == '?') {
      queryBuilder.deleteCharAt(queryBuilder.length() - 1);
    }
    return queryBuilder.toString();
  }
Example #4
0
File: B.java Project: hiuchida/exam
 void solve() {
   int n = readNum();
   int[] num = readNums();
   int[] a = new int[n];
   int[] b = new int[n];
   int[] r = new int[n];
   for (int i = 1; i <= n; i++) {
     r[num[i - 1] - 1] = i;
   }
   for (int i = 1; i <= n; i++) {
     a[i - 1] = 30000 * i;
     b[i - 1] = 30000 * (n - i + 1) + r[i - 1];
   }
   for (int i = 0; i < n; i++) {
     sb.append(a[i]).append(" ");
   }
   sb.deleteCharAt(sb.length() - 1);
   pln(sb.toString());
   sb.delete(0, sb.length());
   for (int i = 0; i < n; i++) {
     sb.append(b[i]).append(" ");
   }
   sb.deleteCharAt(sb.length() - 1);
   pln(sb.toString());
 }
  /** remove leading spaces */
  public static final String stripSpaces(final String data) {
    final StringBuilder text = new StringBuilder((data));

    // strip leading chars
    while (text.length() > 0) {
      if (text.charAt(0) != ' ') {
        break;
      }
      text.deleteCharAt(0);

      // strip ending chars
      int pointer2 = text.length() - 1;
      while (pointer2 > 0) {
        if (text.charAt(pointer2) != ' ') {
          break;
        }
        text.deleteCharAt(pointer2);
        pointer2--;
        if (pointer2 < 0) {
          break;
        }
      }
    }
    return text.toString();
  }
Example #6
0
  /**
   * List the entities in JSON format
   *
   * @param entities entities to return as JSON strings
   */
  public static String writeJSON(Iterable<Entity> entities) {
    logger.log(Level.INFO, "creating JSON format object");
    StringBuilder sb = new StringBuilder();

    int i = 0;
    sb.append("{\"data\": [");
    for (Entity result : entities) {
      Map<String, Object> properties = result.getProperties();
      sb.append("{");
      if (result.getKey().getName() == null)
        sb.append("\"name\" : \"" + result.getKey().getId() + "\",");
      else sb.append("\"name\" : \"" + result.getKey().getName() + "\",");

      for (String key : properties.keySet()) {
        Object object = properties.get(key);
        if (object instanceof Text) {
          Text value = (Text) properties.get(key);
          sb.append("\"" + key + "\" : \"" + value.getValue() + "\",");
          // logger.info(value.getValue());//debug;
        } else {
          sb.append("\"" + key + "\" : \"" + properties.get(key) + "\",");
        }
      }
      sb.deleteCharAt(sb.lastIndexOf(","));
      sb.append("},");
      i++;
    }
    if (i > 0) {
      sb.deleteCharAt(sb.lastIndexOf(","));
    }
    sb.append("]}");
    return sb.toString();
  }