Here you can find the source of charCount(final String s, final char c)
Parameter | Description |
---|---|
s | String to parse |
c | Char to find |
public static final int charCount(final String s, final char c)
//package com.java2s; /*//from www .ja v a 2 s . co m * Corsen development code * * This code may be freely distributed and modified under the * terms of the GNU General Public Licence version 2 or later. This * should be distributed with the code. If you do not have a copy, * see: * * http://www.gnu.org/licenses/gpl-2.0.txt * * Copyright for this code is held jointly by the microarray platform * of the ?cole Normale Sup?rieure and the individual authors. * These should be listed in @author doc comments. * * For more information on the Corsen project and its aims, * or to join the Corsen google group, visit the home page * at: * * http://transcriptome.ens.fr/corsen * */ public class Main { /** * Get the number of the occurence of a char in a string. * @param s String to parse * @param c Char to find * @return the number of the char occurence */ public static final int charCount(final String s, final char c) { if (s == null) return 0; final int len = s.length(); int count = 0; for (int i = 0; i < len; i++) if (s.charAt(i) == c) count++; return count; } }