标签: string-search

在c中的文件中搜索字符串

我正在尝试编写一个可以搜索文件(称为student.txt)中的字符串的程序。我希望我的程序在文件中找到相同的单词时打印该单词,但它显示错误。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
int num =0;
char word[2000];
char *string[50];

FILE *in_file = fopen("student.txt", "r");
//FILE *out_file = fopen("output.txt", "w");

if (in_file == NULL)
{
    printf("Error file missing\n");
    exit(-1);
}

while(student[0]!= '0')
{
    printf("please enter a word(enter 0 to end)\n");
    scanf("%s", student);


    while(!feof(in_file))
    {
        fscanf(in_file,"%s", string);
        if(!strcmp(string, student))==0//if match found
        num++;
    }
    printf("we found the word %s in the file %d times\n",word,num );
    num = 0;
}

return 0; …
Run Code Online (Sandbox Code Playgroud)

c string search string-search data-structures

4
推荐指数
1
解决办法
4万
查看次数

对于字符串,查找和替换

查找一些文本并将其替换为C字符串中的新文本可能比预期的要复杂一些.我正在寻找一种快速且时间复杂度较低的算法.

我该怎么用?

c algorithm string-search

3
推荐指数
1
解决办法
2万
查看次数

什么时候Rabin Karp比KMP或Boyer-Moore更有效?

我正在学习字符串搜索算法,并了解它们如何工作,但还没有找到关于在哪种情况下Rabin-Karp算法比KMP或Boyer-Moore更有效的答案。我看到它更容易实现,不需要相同的开销,但是除此之外,我没有任何线索。

那么,什么时候Rabin-Karp比其他更好?

string-search boyer-moore knuth-morris-pratt rabin-karp

3
推荐指数
1
解决办法
618
查看次数

指定字符串搜索的列和行

因为我正在使用一个非常复杂的表,在变量位置有令人讨厌的重复值,所以我想在特定的行和列之间进行字符串搜索.

例如:

table={{"header1", "header2", "header3", 
 "header4"}, {"falsepositive", "falsepositive", "name1", 
 "falsepositive"}, {"falsepositive", "falsepositive", "name2", 
 "falsepositive"}, {"falsepositive", "falsepositive", 
 "falsepositive", "falsepositive"}}

%//TableForm=
 header1          header1          header1          header1
 falsepositive    falsepositive    name1            falsepositive
 falsepositive    falsepositive    name2            falsepositive
 falsepositive    falsepositive    falsepositive    falsepositive
Run Code Online (Sandbox Code Playgroud)

我如何查找字符串,例如,在第三列,第一行到第二行?

我想用来Which根据字符串在表中的位置来分配值.

例如,

Which[string matched in location one, value, matched in location two, value2]
Run Code Online (Sandbox Code Playgroud)

wolfram-mathematica row string-search

2
推荐指数
1
解决办法
426
查看次数

freebase使用什么算法来匹配名称?

我正在尝试使用他们的四维转储构建本地版本的freebase搜索API.我想知道他们用什么算法来匹配名字?例如,如果你去freebase.com并输入"徒步旅行",你会得到

  • "Apo徒步旅行社"
  • "徒步旅行"
  • "远足格鲁吉亚"
  • "远足弗吉尼亚州的国家森林"
  • "爬山径"

search freebase string-search

2
推荐指数
1
解决办法
452
查看次数

.includes() 算法和速度?

我很想知道 .includes() 方法使用什么算法?它是否使用像 rabin karp 这样的模块化哈希?

在不了解更多关于它的方法和速度的情况下,我对使用 .includes() 有点犹豫。我发现的文档在讨论时没有详细说明(例如https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes

javascript hash string-search

2
推荐指数
1
解决办法
2444
查看次数

从char数组中获取当前单词的最有效方法

假设我有一个字符串"text",一个插入位置"插入符号",然后想要找到当前的单词(按空格分隔).

我目前的做法似乎效率低下,我想知道是否有人有一个有效的方法吗?

const char* text;
int caret;
int initpos;
int start;
int count = 0;
char word[256];

// text and caret values assigned here.

initpos = caret;
while(caret > 0 && text[caret] != ' ') // get start
{
    caret--;
    count++;
}
start = caret;
caret = initpos;

while(text[caret] && text[caret] != ' ') // get end
{
    caret++;
    count++;
}

word = strsub(text, start, count);
Run Code Online (Sandbox Code Playgroud)

c optimization string-search

1
推荐指数
1
解决办法
990
查看次数

如何按顺序检查字符串中的单词

所以我的代码看起来像这样

string order = "Im sending you big apples x100";
string[] fruits = { "apples", "big apples", "oranges" };
string[] vegetables = { "tomatoes", "carrots", "cucumber" };

string[] words = order.Split();

if (fruits.Any(w => words.Contains(w)))
{
  //do things here
}
if (vegetables.Any(w => words.Contains(w)))
{
  //do things here
}
Run Code Online (Sandbox Code Playgroud)

我希望能够找到依赖于顺序字符串的确切内容,如果可能的话,现在在我的情况下,当字符串数组有2个单词的顺序时,这个代码不起作用,当我的字符串数组有2个单词时,我怎么能这样做.我想找到只有它有"大苹果"我知道我只能做"苹果",但我想在订单字符串中找到序列字.

c# string string-matching string-search

1
推荐指数
1
解决办法
3520
查看次数

从输入字符串中的数组中搜索关键字并打印它们

我几乎在过去的几天里一直这样做,但仍然无法获得所需的输出.好吧,我有一个数组说 wordlist[]={"One","Two","Three","Four","Five"}; ,然后我接受用户的输入.

String input="I have three no, four strings";
Run Code Online (Sandbox Code Playgroud)

现在我想要做的是对字符串执行搜索操作以检查数组wordlist []中可用的单词; 与上面的示例类似,输入字符串包含数组中存在的单词three和four.所以它应该能够从字符串中可用的数组中打印出这些单词,如果没有wordlist []中的单词可用,那么它应该打印"No Match Found".

这是我的代码我很震惊.请

import java.util.regex.*;
import java.io.*;
class StringSearch{
    public static void main(String ...v)throws IOException{
        BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
        String wordlist[]={"one","two","three","four","five"};
        String input=cin.readLine();
        int i,j;
        boolean found;
        Pattern pat;
        Matcher mat;
        Pattern spliter=Pattern.compile("[ ,.!]");
        String ip[]=spliter.split(input);
        System.out.println(ip[2]);
        for(i=0; i<wordlist.length;i++){
            for(j=0;j<ip.length;j++){
                pat=Pattern.compile("\b"+ip[j]+"\b");
                mat=pat.matcher(wordlist[i]);
                if(){
                        // No Idea What to write here
                }
            }
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

java regex string search string-search

1
推荐指数
1
解决办法
954
查看次数

具有近似字符串匹配功能的Android autocompletetextview

我正在开发一个有大约8000个印度城市名称的应用程序.当用户输入i时,使用auto complete来帮助用户完成工作.但是一些城市名称的拼写很难为来自其他州的人们猜测.所以我们需要一个近似的字符串匹配来自动完成而不是默认的精确匹配.

例如,有像这样的名字

  • Thirumayilai
  • Thirunettur
  • Thiruthuraiyur
  • 蒂鲁瓦鲁尔

并且

  • 蒂鲁内尔维利
  • 蒂鲁芒格阿拉姆

如果用户搜索城市'Tirunelveli'但在文本框中键入'Thirunel',则autocompletetextview不会显示名称,并且它会进行精确的字符串匹配.

我该怎么做才能在自动完成下拉列表中获得近似匹配字符串..

android string-search autocompletetextview

0
推荐指数
1
解决办法
1982
查看次数

在批处理脚本中搜索文本文件中的字符串

如何逐行搜索文本文件中的字符串,并在找到匹配项时将找到匹配项的整行复制到变量中?

基本上,我有一个文本文件,其中包含文件夹中所有子文件夹的地址/路径。我想在这个文本文件中搜索一个字符串(该字符串将只匹配一行的一部分),如果有匹配项,我想将整行复制到一个变量中。

该字符串来自文件名,一旦文本文件中有匹配项,我想使用子文件夹地址将文件移动到那里。

这是我迄今为止所做的:

@ECHO off
::Reads all the folders and subfolders existing in the "root1" folder and   writes the path for each foleder/subfolder into the "1.txt" file
dir /b /s /a:d "...\root1" > "...\1.txt"

::Reads all the files existing in "root2" folder and writes the path of each file into the "2.txt" file
dir /s /b "...\root2\" > "...\2.txt"

SETLOCAL EnableDelayedExpansion

::reads the last file path from the "2.txt" and asign it to a variable
for /f "delims=" %%x …
Run Code Online (Sandbox Code Playgroud)

batch-file text-search string-search

0
推荐指数
1
解决办法
3万
查看次数

检查单词是否包含一个或多个星号

我在Stack Overflow上提到了一些与此相关的帖子.但是我并没有真正找到一种非常有说服力的方法.

我将如何使用函数返回True或False,具体取决于单词(输入到函数)是否包含0或1(或更多)星.

我试过这样的事情:

def ANY_CHAR_IS_star(word):
    return bool(re.match(r"^[*]?", word))
Run Code Online (Sandbox Code Playgroud)

然而,对于错误情况,这也是正确的.不知道哪里出错了.诚实地说正则表达式有点弱

python string-matching string-search python-3.x

-3
推荐指数
1
解决办法
434
查看次数