在不使用正则表达式之前和之后输出字符串向量'word'。制定相关程序
Output a vector of strings before and after 'word' NOT using regex. Making concordance program
我正在开发一个索引程序,目前正在研究getContext函数。我需要这个函数的工作方式有点像正则表达式,但我希望它在指定单词之前和之后返回字符串向量。我不知道我的想法是否正确,但这是我能想到的。
所以这就是我想到的:它接受一个单词并创建两个向量,并在指定单词的左侧和右侧返回一个向量。
谢谢:D
我认为我不需要包含整个代码文件,但如果有人需要它,我也可以把它放上去。
/* Get context for input parameter word (case-insensitive comparison)
* Return a dynamically allocated vector of strings, each string
* consisting of contextSize number of words before word and contextSize
* number of words after word, with word in the middle (set off with "<<"
* before the word and ">>" after the word). ContextSize defaults to 5.
* It is user's responsibility to delete the vector.
*/
vector<string>*Concordance::getContext(string word, int contextSize = 5){
vector<string> before;
vector<string> after;
return 0;
}
如果您只是在std::vector<std::string>
中寻找std::string
,那么您可以使用std::find
bool IsWordInArrayOfWords(const std::vector<string>& arrayOfWords, const std::string& word)
{
auto found = std::find(arrayOfWords.cbegin(), arrayOfWords.cend(), word);
return found != arrayOfWords.cend();
}
如果您正在寻找一种方法来搜索单词的部分匹配和基于百分比或其他更复杂的上下文的最佳匹配,并且正则表达式不是一种选择,那么我认为我们需要更好地描述您要解决的内容以及您要解决的真正问题是什么。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- C++可以从文本文件复制并粘贴到打开的Word程序中
- 初学者 - 我的"produce word backwards"程序有什么问题?
- 将多个图像从QT应用程序拖到MS Word
- 尝试用C++编写Word Wrap程序
- 从c++程序访问Microsoft Word文档
- 从c++代码控制不同的应用程序(Adobe Reader,Word,Windows Media Player,Power
- 在不使用正则表达式之前和之后输出字符串向量'word'。制定相关程序
- 在我的c++程序中打开Microsoft Word