How to split a string into words. Ex: “stringintowords” -> “String Into Words”?

前端 未结 13 1211
粉色の甜心
粉色の甜心 2020-11-29 20:18

What is the right way to split a string into words ? (string doesn\'t contain any spaces or punctuation marks)

For example: \"stringintowords\" -> \"String Into Word

13条回答
  •  萌比男神i
    2020-11-29 20:43

    Actually, with the dictionary this problem can be solved in O(n) time. More precisely in (k + 1) * n at worst, where n is the number of characters in the string and k is the length of the longest word in the dictionary.

    Besides, the algorithm allows you to skip junk.

    Here's the working implementation in Common Lisp I've created some time ago: https://gist.github.com/3381522

提交回复
热议问题