Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 处理字符串工具类
- * @author chexun
- */
- public class StringUtil {
- /**
- * 截取服务记录有效长度
- * @param record 服务记录
- * @param wd 热词
- * @param beginIndex 热词前长度
- * @param endIndex 热词后长度
- * @return 服务记录子串
- */
- public static String getSubString(String record,String wd,int beginIndex,int endIndex) {
- String serviceRecord = null;
- int len = record.length();
- int index = record.indexOf(wd);
- int wdLen = wd.length();
- int fromIndex = 0;
- int toIndex = len;
- if (index > -1) {
- if ((index - beginIndex) > fromIndex) {
- fromIndex = index - beginIndex;
- }
- if ((index + wdLen + endIndex) < len) {
- toIndex = index + wdLen + endIndex;
- }
- serviceRecord =record.substring(fromIndex, toIndex);
- }
- return serviceRecord;
- }
- }
Add Comment
Please, Sign In to add comment