Here you can find the source of countSubString(final String aString, final String aSubString)
Parameter | Description |
---|---|
aString | a parameter |
aSubString | a parameter |
public static int countSubString(final String aString, final String aSubString)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 www.isandlatech.com (www.isandlatech.com) * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://w w w. j a va 2s.c o m * ogattaz (isandlaTech) - initial API and implementation *******************************************************************************/ public class Main { /** * @param aString * @param aSubString * @return the number of the searched sub-string int the string */ public static int countSubString(final String aString, final String aSubString) { if (aString == null || aSubString == null || aString.isEmpty() || aString.length() < aSubString.length()) { return -1; } String[] wSplited = aString.split(aSubString); return wSplited.length - 1; } }