Here you can find the source of chopAtWordsAround(String input, String wordList[], int numChars)
public static String chopAtWordsAround(String input, String wordList[], int numChars)
//package com.java2s; /**/* w w w . j ava 2s .c o m*/ * $Revision $ * $Date $ * * Copyright (C) 2005-2010 Jive Software. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static String chopAtWordsAround(String input, String wordList[], int numChars) { if (input == null || "".equals(input.trim()) || wordList == null || wordList.length == 0 || numChars == 0) return ""; String lc = input.toLowerCase(); String arr$[] = wordList; int len$ = arr$.length; for (int i$ = 0; i$ < len$; i$++) { String aWordList = arr$[i$]; int pos = lc.indexOf(aWordList); if (pos > -1) { int beginIdx = pos - numChars; if (beginIdx < 0) beginIdx = 0; int endIdx = pos + numChars; if (endIdx > input.length() - 1) endIdx = input.length() - 1; char chars[]; for (chars = input.toCharArray(); beginIdx > 0 && chars[beginIdx] != ' ' && chars[beginIdx] != '\n' && chars[beginIdx] != '\r'; beginIdx--) ; for (; endIdx < input.length() && chars[endIdx] != ' ' && chars[endIdx] != '\n' && chars[endIdx] != '\r'; endIdx++) ; return input.substring(beginIdx, endIdx); } } return input.substring(0, input.length() < 200 ? input.length() : 200); } }