开发者

String searching algorithm [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜