Guest User

Untitled

a guest
Jan 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /**
  2. * 处理字符串工具类
  3. * @author chexun
  4. */
  5. public class StringUtil {
  6.  
  7. /**
  8. * 截取服务记录有效长度
  9. * @param record 服务记录
  10. * @param wd 热词
  11. * @param beginIndex 热词前长度
  12. * @param endIndex 热词后长度
  13. * @return 服务记录子串
  14. */
  15. public static String getSubString(String record,String wd,int beginIndex,int endIndex) {
  16. String serviceRecord = null;
  17. int len = record.length();
  18. int index = record.indexOf(wd);
  19. int wdLen = wd.length();
  20. int fromIndex = 0;
  21. int toIndex = len;
  22. if (index > -1) {
  23. if ((index - beginIndex) > fromIndex) {
  24. fromIndex = index - beginIndex;
  25. }
  26. if ((index + wdLen + endIndex) < len) {
  27. toIndex = index + wdLen + endIndex;
  28. }
  29. serviceRecord =record.substring(fromIndex, toIndex);
  30. }
  31. return serviceRecord;
  32. }
  33. }
Add Comment
Please, Sign In to add comment