Java StringBuilder.charAt Examples

Java StringBuilder.charAt - 30 examples found. These are the top rated real world Java examples of StringBuilder.charAt extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private String readLine(ServletInputStream in) throws IOException {
    StringBuilder sbuf = new StringBuilder();
    int result;
    do {
      result = in.readLine(buf, 0, buf.length); // does +=
      if (result != -1) {
        sbuf.append(new String(buf, 0, result, encoding));
      }
    } while (result == buf.length); // loop only if the buffer was filled

    if (sbuf.length() == 0) {
      return null; // nothing read, must be at the end of stream
    }

    // Cut off the trailing \n or \r\n
    // It should always be \r\n but IE5 sometimes does just \n
    // Thanks to Luke Blaikie for helping make this work with \n
    int len = sbuf.length();
    if (len >= 2 && sbuf.charAt(len - 2) == '\r') {
      sbuf.setLength(len - 2); // cut \r\n
    } else if (len >= 1 && sbuf.charAt(len - 1) == '\n') {
      sbuf.setLength(len - 1); // cut \n
    }
    return sbuf.toString();
  }
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input = new Scanner(System.in);
    int times = Integer.parseInt(input.next());
    for (int x = 0; x < times; x++) {
      String next = input.next();
      int pos = (next.length() - 1) / 2;
      String res = "";
      StringBuilder build = new StringBuilder(next);
      String middle = "";
      if (next.length() % 2 == 0) {
        boolean carry = false;

        for (; pos >= 0; pos--) {
          int left = Character.getNumericValue(build.charAt(pos));
          int right = Character.getNumericValue(build.charAt(build.length() - 1 - pos));
          if (left < right) {
            left++;
            build.setCharAt(pos, Character.forDigit(left, 10));
            break;
          } else {

          }
        }
      } else {

      }

      System.out.println(res);
    }
  }
      /** {@inheritDoc} */
      @Override
      public ByteString normalizeValue(ByteSequence value) throws DirectoryException {
        StringBuilder buffer = new StringBuilder();
        prepareUnicode(buffer, value, TRIM, CASE_FOLD);

        int bufferLength = buffer.length();
        if (bufferLength == 0) {
          if (value.length() > 0) {
            // This should only happen if the value is composed entirely
            // of spaces. In that case, the normalized value is a single space.
            return SINGLE_SPACE_VALUE;
          } else {
            // The value is empty, so it is already normalized.
            return ByteString.empty();
          }
        }

        // Replace any consecutive spaces with a single space.
        for (int pos = bufferLength - 1; pos > 0; pos--) {
          if (buffer.charAt(pos) == ' ') {
            if (buffer.charAt(pos - 1) == ' ') {
              buffer.delete(pos, pos + 1);
            }
          }
        }

        return ByteString.valueOf(buffer.toString());
      }
  private String readLine(int ci) {
    int last_ch = -1;

    fTmpBuffer.setLength(0);
    while (ci != -1 && ci != '\n' || last_ch == '\\') {
      if (last_ch == '\\' && ci == '\n') {
        if (fTmpBuffer.charAt(fTmpBuffer.length() - 1) == '\r') {
          fTmpBuffer.setLength(fTmpBuffer.length() - 1);
        }
        if (fTmpBuffer.charAt(fTmpBuffer.length() - 1) == '\\') {
          fTmpBuffer.setCharAt(fTmpBuffer.length() - 1, '\n');
        }
      } else {
        fTmpBuffer.append((char) ci);
      }

      if (ci != '\r') {
        last_ch = ci;
      }

      ci = get_ch();
    }

    unget_ch(ci);

    if (fTmpBuffer.length() == 0) {
      return null;
    } else {
      return fTmpBuffer.toString();
    }
  }
Example #5
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();
  }
 @TCB
 private static void stripBannedCodeunits(StringBuilder sb, int start) {
   int k = start;
   for (int i = start, n = sb.length(); i < n; ++i) {
     char ch = sb.charAt(i);
     if (ch < 0x20) {
       if (IS_BANNED_ASCII[ch]) {
         continue;
       }
     } else if (0xd800 <= ch) {
       if (ch <= 0xdfff) {
         if (i + 1 < n) {
           char next = sb.charAt(i + 1);
           if (Character.isSurrogatePair(ch, next)) {
             sb.setCharAt(k++, ch);
             sb.setCharAt(k++, next);
             ++i;
           }
         }
         continue;
       } else if ((ch & 0xfffe) == 0xfffe) {
         continue;
       }
     }
     sb.setCharAt(k++, ch);
   }
   sb.setLength(k);
 }