C FIND函数用法

合集下载

C中使用FindWindow函数详解从标题获取句柄

C中使用FindWindow函数详解从标题获取句柄

C#中使用Fi‎n dWin‎d ow函数‎详解从标题获取‎句柄FindW‎i ndow‎用来根据类‎名和窗口名‎来得到窗口‎句柄的。

但是这个函‎数不能查找‎子窗口,也不区分大‎小写。

如果要从一‎个窗口的子‎窗口中查找‎需要使用F‎i ndWi‎n dowE‎X。

1.在C#中使用方法‎如下:[DllIm‎p ort("User3‎2.dll", Entry‎P oint‎= "FindW‎i ndow‎")]priva‎t e stati‎c exter‎n IntPt‎r FindW‎i ndow‎(strin‎glpCla‎s sNam‎e,strin‎g lpWin‎d owNa‎m e);[DllIm‎p ort("User3‎2.dll", Entry‎P oint‎= "FindW‎i ndow‎E x")]priva‎t e stati‎c exter‎n IntPt‎r FindW‎i ndow‎E x(IntPt‎r hwndP‎a rent‎, IntPt‎r hwndC‎h ildA‎f ter, strin‎g lpCla‎s sNam‎e, strin‎g lpWin‎d owNa‎m e); [DllIm‎p ort("User3‎2.dll", Entry‎P oint‎= "FindW‎i ndow‎")]priva‎t e stati‎c exter‎n IntPt‎r FindW‎i ndow‎(strin‎glpCla‎s sNam‎e,strin‎g lpWin‎d owNa‎m e);[DllIm‎p ort("User3‎2.dll", Entry‎P oint‎= "FindW‎i ndow‎E x")]priva‎t e stati‎c exter‎n IntPt‎r FindW‎i ndow‎E x(IntPt‎r hwndP‎a rent‎, IntPt‎r hwndC‎h ildA‎f ter, strin‎g lpCla‎s sNam‎e, strin‎g lpWin‎d owNa‎m e);2. 实例参考:IntPt‎r hWnd = FindW‎i ndow‎(null, "test Demo");这样会查找‎所有tit‎l e是"test Demo"的窗口。

find函数的用法

find函数的用法

find函数的用法find函数是C语言中常用的函数,它的作用是在字符串中查找指定的字符串子串。

具体来说,它查找所传递的参数字符串在字符串中第一次出现的位置。

如果查找成功,返回该字符串在字符串中第一次出现的位置;如果查找失败,返回-1。

find函数的声明及用法如下:size_t find (const char* str1, const char* str2);其中,str1是要检索的字符串,str2是要查找的子串。

例如,让我们来检查字符串s1中是否存在子串s2:int result = find(s1,s2);如果result的值不等于-1,则表示字符串s1中包含子串s2,检索成功;如果result的值等于-1,则表示字符串s1中不包含子串s2,检索失败。

以下是一个简单的find函数的使用实例:#include <stdio.h>#include <string.h>int main(){char str1[50], str2[20];int result;printf(输入主串:scanf(%sstr1);printf(输入子串:scanf(%sstr2);result = find(str1,str2);if(result == -1){printf(在字符串中没有找到子串}else{printf(在字符串中找到子串,位置为%dresult);}return 0;}此外,find函数还可以用于查找任何类型的字符数组,如字符数组、整数数组、浮点数数组等,只要它们可以被视为字符串,就可以使用find函数查找。

简而言之,find函数是一种功能强大的查找函数,可以用来快速查找字符串中的指定子串,它也可以用于查找任何类型的字符数组,比如字符数组、整数数组、浮点数数组等。

尽管find函数具有许多优点,但也有一些缺点需要注意。

首先,它只能查找一个子串,无法查找多个子串;其次,它只能返回字符串第一次出现的位置,无法返回其他位置的子串。

c语言findnext函数

c语言findnext函数

c语言findnext函数Findnext函数在C语言中是一种搜索指定的文件的函数。

它有两种使用方法:一种是用于搜索指定文件夹中的文件,另一种是用于搜索指定文件夹中的子文件夹。

Findnext函数用法:1、在调用Findnext之前,需要先调用Findfirst函数,以初始化搜索操作2、Findnext函数的声明:int _findnext(long handle, struct _finddata_t *fileinfo);参数handle:是Findfirst函数返回的句柄。

参数fileinfo:是一个结构体变量,该变量的定义:struct _finddata_t{ttunsigned int attrib; //文件的属性tttime_t time_create; //文件创建时间tttime_t time_access; //文件访问时间tttime_t time_write; //文件修改时间tt_fsize_t size; //文件的大小ttchar name[260]; //文件名};3、Findnext函数的用法://搜索d:temptemp1目录下的所有文件long handlde;handlde = _findfirst('d:temptemp1*.*', &fileinfo); if(handlde==-1){t//搜索失败tprintf('Search Failed!');treturn -1;}//搜索d:temptemp1目录下的文件while(_findnext(handlde, &fileinfo) == 0)t{ttprintf('File na %s', );ttprintf('File size:%d', fileinfo.size);ttprintf('Create ti%s', ctime(&fileinfo.time_create));ttprintf('Access ti%s', ctime(&fileinfo.time_access));ttprintf('Write ti%s', ctime(&fileinfo.time_write));t}//搜索完毕,关闭句柄_findclose(handlde);以上就是Findnext函数的用法,通过Findnext函数可以搜索指定文件夹下的所有文件,可以得到文件的名称、大小、创建时间、访问时间和修改时间等信息。

c语言find函数

c语言find函数

c语言find函数
C语言中的Find函数是一个非常重要的函数,它可以在字符数组或字符串中搜索给定的字符串。

它的使用非常广泛,在任何有关字符的C语言程序中都可以使用。

Find函数的基本用法是:char* find (char *s, char *t),其中s表示要搜索的字符串,t表示要查找的字符串。

如果搜索到了t 字符串,那么返回t字符串在s字符串中出现的第一个字符的地址;如果没有搜索到t字符串,则返回null。

Find函数的实现有两种方法:一种是使用strstr()函数,这种方法的执行效率比较高,但是在查找过程中容易出现漏搜索的情况;另一种是使用strncmp()函数,这种方法的执行效率较低,但可以避免出现漏搜索的情况。

在实际应用中,Find函数常常被用来检索特定字符串。

例如,在某些场合可能需要判断字符串中是否含有特定字符或字符串,这时就可以使用Find函数来完成这一需求。

此外,Find函数还可以用于实现字符串的比较,例如可以用来比较两个字符串的大小,若一个字符串中的某个子字符串,比另一个字符串中的同一子字符串索引大,则说明前一个字符串大小大于后一个字符串,反之亦然。

另外,Find函数还有一些其它用途,例如在文件或其他数据结构中查找某个特定字符。

可以使用Find函数来实现字符串的搜索,只要每次搜索得到一个相同的字符,就可以判断文件或其他数据结构
中是否存在该字符。

总之,Find函数在C语言中十分重要,它提供了一种非常实用的字符串搜索方式,可以应用于字符串的比较、查找特定字符串以及检索文件或其他数据结构等。

因此,Find函数在C语言开发中可以起到很好的辅助作用,十分实用。

C++中find()函数和rfind()函数的用法

C++中find()函数和rfind()函数的用法

C++中find()函数和rfind()函数的⽤法本⽂转载⾃string中 find()的应⽤(rfind() 类似,只是从反向查找)原型如下:(1)size_t find (const string& str, size_t pos = 0) const; //查找对象--string类对象(2)size_t find (const char* s, size_t pos = 0) const; //查找对象--字符串(3)size_t find (const char* s, size_t pos, size_t n) const; //查找对象--字符串的前n个字符(4)size_t find (char c, size_t pos = 0) const; //查找对象--字符结果:找到 -- 返回第⼀个字符的索引没找到--返回 string::npos⽰例:1 #include <iostream> // std::cout2 #include <string> // std::string34int main ()5 {6 std::string str ("There are two needles in this haystack with needles.");7 std::string str2 ("needle");89// different member versions of find in the same order as above:10 std::size_t found = str.find(str2);11if (found!=std::string::npos)12 std::cout << "first 'needle' found at: " << found << '\n';1314 found=str.find("needles are small",found+1,6);15if (found!=std::string::npos)16 std::cout << "second 'needle' found at: " << found << '\n';1718 found=str.find("haystack");19if (found!=std::string::npos)20 std::cout << "'haystack' also found at: " << found << '\n';2122 found=str.find('.');23if (found!=std::string::npos)24 std::cout << "Period found at: " << found << '\n';2526// let's replace the first needle:27 str.replace(str.find(str2),str2.length(),"preposition"); //replace ⽤法28 std::cout << str << '\n';2930return0;31 }结果:first 'needle' found at: 14second 'needle' found at: 44'haystack' also found at: 30Period found at: 51There are two prepositions in this haystack with needles其他还有 find_first_of(), find_last_of(), find_first_not_of(), find_last_not_of()作⽤是查找字符串中任⼀个字符满⾜的查找条件string snake1("cobra");int where = snake1.find_first_of("hark");返回3 因为 "hark"中各⼀个字符在 snake1--cobra 中第⼀次出现的是字符'r'(3为 cobra 中'r'的索引)同理:int where = snake1.find_last_of("hark");返回4 因为 "hark"中各⼀个字符在 snake1--cobra 中最后⼀次出现的是字符'a'(3为 cobra 中'r'的索引)其他同理。

C#中Find及Findindex用法

C#中Find及Findindex用法

C#中Find及Findindex用法Findindex及find中需要一个参数,可用一个Lambda表达式来表示。

Findindex返回查找内容在列表中的位置,find返回参数相同类型的对象。

注意,如果找不到会报错哦,所以最好加上try.示例如下:假设有一个list,里面有10组数据,每组数据我都放到一个class 中。

现在演示一下查找的方法。

以下是用来表示数据的class,其实用struct也是一样的public class MyInfo{public int age;public double value;public string name;}代码调用:List<MyInfo> mystr=new List<MyInfo>(); //创建一个存储数据的LISTint []agearray=new int[]{20,30,60,14,16,42,34,45,22,31};string []names=new string[]{'A','B','C','D','E','F','G','H','I','J'};for(int i=0;i<10;i++)//将数据放入LIST中{MyInfo stem=new MyInfo();=names[i];stem.age=agearray[i];stem.value=i/3;mystr.Add(stem);}try//防止查找内容不存在的出错{int iage=mystr.Find(a=>=='C').age;//查找名称为“C“的人的年龄lbLog.Items.Add('Find people C's age,result: '+iage.ToString());//在listbox(lbLog)中显示string sname=mystr.Find(a=>a.age==34).name;//查找年龄为34的人名lbLog.Items.Add('Find the people name whose age is 34,Result: '+sname);//在listbox(lbLog)中显示int imatch=mystr.FindIndex(a=>=='D');//查找是否存在叫'D'的人,返回list中有位置lbLog.Items.Add('Find match item is: '+imatch.ToString());//在listbox(lbLog)中显示}catch{lbLog.Items.Add('Can't find anything!');}。

c++的find函数

c++的find函数

c++的find函数C++提供了`std::find`函数,用于在给定的数组或列表中查找指定的元素。

该函数返回一个指向原始数组或列表中指定元素元素的指针或引用,如果该元素在数组或列表中未被找到,则返回`std::out_of_range`异常。

下面是`std::find`函数的示例用法:```c++#include <iostream>#include <vector>#include <find>int main() {// 输入一个整数数组std::vector<int> numbers = { 1, 2, 3, 4, 5 };std::cout << std::find(numbers.begin(), numbers.end(), 10) << std::endl; // 输出 1std::cout << std::find(numbers.begin(), numbers.end(), 20) << std::endl; // 输出未找到// 输入一个字符串数组std::vector<std::string> words = {"apple", "banana", "orange", "grape"};std::cout << std::find(words.begin(), words.end(), "grape") << std::endl; // 输出 1std::cout << std::find(words.begin(), words.end(), "banana") << std::endl; // 输出未找到return 0;}```在上面的示例中,我们首先定义了一个整数数组和一个字符串数组。

c语言find函数用法详解

c语言find函数用法详解

在C语言中,find函数本身并不存在,但是你可能在其他编程语言中经常见到。

在C语言中,查找数组或其他数据结构的元素通常使用线性搜索、二分搜索或其他算法实现。

如果你需要在C语言中查找元素,可以使用循环结构手动实现查找操作。

以下是一个使用循环实现线性搜索的简单示例:#include <stdio.h>int find(int array[], int size, int target) {for (int i = 0; i < size; i++) {if (array[i] == target) {return i; // 找到目标,返回索引}}return -1; // 未找到目标,返回-1}int main() {int numbers[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};int size = sizeof(numbers) / sizeof(numbers[0]);int target = 7;int index = find(numbers, size, target);if (index != -1) {printf("元素%d 在数组中的索引是%d。

\n", target, index);} else {printf("元素%d 未在数组中找到。

\n", target);}return 0;}这是一个非常基础的线性搜索实现。

如果你的数组有序,你可能会考虑使用二分搜索等更高效的算法。

请注意,C 语言并没有内置的find 函数,具体的查找操作需要根据实际需求手动实现。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
查找从指定位置开始的第一次出现的目标字符串:
/* * Author: mybestwishes * Created Time: 2011/4/9 15:56:44 * File Name: find.cpp */ #include <iostream> #include <cstdio> using namespace std;
int main(){ string s1 = "adedef" ; string s2 = "dek" ; int ans = s1.find_first_of(s2) ; //从 s1 的第二个字符开始查找
子串 s2 cout<<ans<<endl; system("pause");
}
其中 find_first_of()也可以约定初始查找的位 置: s1.find_first_of(s2 , 2) ;
int main(){ string s1 = "adedef" ; string s2 = "de" ; int ans = s1.find(s2,2) ; //从 s1 的第二个字符开始查找子串 s2 cout<<ans<<endl; system("pause");
}
2、find_first_of()
查找子串中的某个字符最先出现的位置。find_first_of()不是全匹配,而 find()是全匹配
/* * Author: mybestwishes * Created Time: 2011/4/9 15:56:44 * File Name: find.cpp */ #include <iostream> #include <cstdio> using namespace std;
C++ STL 里提供了很多字符串操作的函数,下面的字符串查找方面的部分函数 用法简介。
1、find()
查找第一次出现的目标字符串:
/* * Author: mybestwishes * Created Time: 2011/4/9 15:56:44 * File Name: find.cpp */ #include <iostream> #include <cstdio> using namespace std;
int main(){ string s1 = "abcdef" ; string s2 = "de" ; int ans = s1.find(s2) ; //在 s1 中查找子串 s2 cout<<ans<<endl; system("pause");
}
说明:如果查找成功则输出查找到的第一个位置,否则返回-1 ;
3、find_last_of()
这个函数与 find_first_of()功能差不多,只不过 find_first_of()是从字符 串的前面往后面搜索,而 find_last_of()是从字符串的后面往前面搜Байду номын сангаас。可以 自行测试一下。 4、rfind() 反向查找字符串,即找到最后一个与子串匹配的位置。 5、find_first_not_of() 找到第一个不与子串的位置。
相关文档
最新文档