在Eng和Unicode字符串中查找字符串中的单词(每个单词之间没有空格)

时间:2021-05-17 21:36:28

(VB.NET, .NET 3.5)

(VB.NET,.NET 3.5)

I'm trying to write a function to find a word in a string in the this format : "ThisissometextthatIneedtofindandthisisthetext. This is another text."

我正在尝试编写一个函数,以这种格式在字符串中查找单词:“ThisissometextthatIneedtofindandthisisthetext。这是另一个文本。”

It's read as " This is some text that I need to find and this is the text. This is another text." but there is no space between each word. I want to get the word "text" or any word in that string. Can you help me with this function with a code sample ?

它被解读为“这是我需要找到的一些文本,这是文本。这是另一个文本。”但每个单词之间没有空格。我希望得到“text”或该字符串中的任何单词。你能用代码示例帮我解决这个问题吗?

And I think that this method can be implemented with a string of Unicode also because in a sentence of Unicode it contains one or few, sometimes zero spaces between each word.

我认为这个方法可以用Unicode字符串实现,因为在Unicode的一个句子中它包含一个或几个,有时在每个单词之间为零。

Thanks.

3 个解决方案

#1


See String.IndexOf(). It does exactly what you want.

请参见String.IndexOf()。它完全符合你的要求。

Actually, after trying to find it in the help file, I've reconsidered my response to your question in the comments. See MSDN for examples and documentation. (Finding it, as simple as it should have been, wasn't so simple. :-)

实际上,在尝试在帮助文件中找到它之后,我在评论中重新考虑了我对您的问题的回答。有关示例和文档,请参阅MSDN。 (找到它,就像它应该的那样简单,并不那么简单。:-)

#2


I would look up articles on spell checkers. This is a decent one. I would expect the two problems have very similar solutions.

我会查看关于拼写检查的文章。这是一个体面的。我希望这两个问题有非常相似的解决方案。

#3


To test if a substring exist in a string or unicode, you could use:

要测试字符串或unicode中是否存在子字符串,可以使用:

exists = InStr"ThisissometextthatIneedtofindandthisisthetext. This is another text.", "text") <> 0

#1


See String.IndexOf(). It does exactly what you want.

请参见String.IndexOf()。它完全符合你的要求。

Actually, after trying to find it in the help file, I've reconsidered my response to your question in the comments. See MSDN for examples and documentation. (Finding it, as simple as it should have been, wasn't so simple. :-)

实际上,在尝试在帮助文件中找到它之后,我在评论中重新考虑了我对您的问题的回答。有关示例和文档,请参阅MSDN。 (找到它,就像它应该的那样简单,并不那么简单。:-)

#2


I would look up articles on spell checkers. This is a decent one. I would expect the two problems have very similar solutions.

我会查看关于拼写检查的文章。这是一个体面的。我希望这两个问题有非常相似的解决方案。

#3


To test if a substring exist in a string or unicode, you could use:

要测试字符串或unicode中是否存在子字符串,可以使用:

exists = InStr"ThisissometextthatIneedtofindandthisisthetext. This is another text.", "text") <> 0