Java String Char Count countChar(String str, char reg)

Here you can find the source of countChar(String str, char reg)

Description

count Char

License

Open Source License

Declaration

public static int countChar(String str, char reg) 

Method Source Code

//package com.java2s;
/*/*from w  w w  . j  ava 2 s. c  o  m*/
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    public static int countChar(String str, char reg) {
        char[] ch = str.toCharArray();
        int count = 0;
        for (int i = 0; i < ch.length; ++i) {
            if (ch[i] == reg) {
                if (ch[i + 1] == reg) {
                    ++i;
                    continue;
                }
                ++count;
            }
        }
        return count;
    }
}

Related

  1. countChar(String sql, int end)
  2. countChar(String src, char c)
  3. countChar(String str, char c)
  4. countChar(String str, char c)
  5. countChar(String str, char chr)
  6. countChar(String string, char c, int pos, boolean forwards)
  7. countChar(String string, String c)
  8. countChar(String text, char c)
  9. countChar(String text, char ch)