开发者

String searching algorithm [closed]

开发者 https://www.devze.com 2023-03-15 11:54 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Can someon开发者_高级运维e recommend me a good code/algorithm for string searching?

I'm using Java.

Example: How many times the word apple appears in a text.


You can try calling method countMatches(source,word) of org.apache.commons.lang.StringUtils.

A small example:

      String string = "How arer you? Who are you?";  
      System.out.println(StringUtils.countMatches(string,"you"));

Also look at this thread: Java Counting # of occurrences of a word in a string


This guy has gone to the trouble of implementing some advanced String search algorithms in Java.


I'd recommend regexp


Several algorithms are detailed on the wikipedia string searching algorithm page. I'd question whether you should be looking at string searching algorithms or just using the functionality already provided by the language.


Check the wiki page if you are looking for more advanced algorithms.

0

精彩评论

暂无评论...
验证码 换一张
取 消