Here you can find the source of countChar(String a_text, char a_character)
Parameter | Description |
---|---|
a_text | the string to search |
a_character | the character to count. |
public static int countChar(String a_text, char a_character)
//package com.java2s; /*//from w w w. j a va 2s . c o m * @(#) StringUtils.java Jul 20, 2005 * Copyright 2005 Frequency Marketing, Inc. All rights reserved. * Frequency Marketing, Inc. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ public class Main { /** * Count the number of a single character that occur in a string. * @param a_text the string to search * @param a_character the character to count. * @return the number of characters in the string. */ public static int countChar(String a_text, char a_character) { int count = 0; String text = a_text; int pos = text.indexOf(a_character); while (pos != -1) { count++; pos = text.indexOf(a_character, pos + 1); } return count; } }