C++中如何用find找出匹配的字符串?其中包含任意字符。
\u8bf7\u95eeC++\u7684\u5b57\u7b26\u4e32find()\u51fd\u6570\u7684\u7528\u6cd5?CString::Find
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
Return Value
The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.
\u8fd9\u662f\u6211\u4eceMSDN\u4e0aCOPY\u4e0b\u6765\u7684
\u610f\u601d\u662f\u8bf4\u4ece\u7b2cnStart\u4e2a\u5b57\u7b26\u5f00\u59cb\u67e5\u627e\u5b57\u7b26ch\u6216\u5b57\u7b26\u4e32pstr\u3002
\u627e\u5230\u7684\u8bdd\u8fd4\u56de\u503c\u662fch\u5728CString\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4f4d\u7f6e
\u627e\u4e0d\u5230\u7684\u8bdd\u8fd4\u56de\u503c-1
zero-based index\u5c31\u662f\u8bf4\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5bf9\u5e94\u7684nstart\u662f0
\u6bd4\u5982\u8bf4
CString test="asdfjkll";
test.find('c')\u7684\u503c\u662f-1
test.find('d')\u7684\u503c\u662f2
\u2026\u2026\u2026\u2026
\u6ce8\u610fFind\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u5f00\u59cb\u4f4d\u7f6e\u3002\u8bb0\u5f55\u7b2c\u4e00\u6b21\u67e5\u627e\u7684\u4f4d\u7f6e\u7ed3\u679c\uff08Find\u8fd4\u503c\uff09\u52a0\u4e0a\u88ab\u67e5\u627e\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u4f5c\u4e3a\u4e0b\u4e00\u6b21\u67e5\u627e\u7684\u8d77\u59cb\u5c31\u53ef\u4ee5\u4e86\uff0c\u4e00\u76f4\u5230\u627e\u4e0d\u5230\u3002
#include<string>void main()
{
string words("abc_12c4def_456F");
string::size_type pos=0;
pos=wods.find("def_456F");//如果找到匹配的字符串,find返回值为匹配字符串的第一个字符的索引位置,如果没有找到,则返回string::size_type npos.这里执行完毕之后,pos值为8
}
绛旓細 鍦ㄧ増鏈枃浠朵腑鍙互浣跨敤涓婅堪鍙橀噺鏉ユ鏌ョ増鏈殑鍏煎鎬с佺増鏈槸鍚鍖归厤锛屽苟璁剧疆濡備笅鍙橀噺浣滀负杩斿洖缁撴灉锛 find_package 浼氭鏌ヤ笂杩板彉閲忥紝濡傛灉鐗堟湰鍖归厤鎴愬姛锛岄偅涔 find_package 浼氳繑鍥炲涓嬪彉閲忕粰璋冪敤鑰咃細 mymath 搴撶殑 CMakeLists.txt 鍐呭濡備笅锛 ...
绛旓細\0"}; printf("\nplease input s1:"); scanf("%s",s1); printf("\nplease input s2:"); scanf("%s",s2); int len1=strlen(s1); int len2=strlen(s2); int i,j,find=0; for(i=0;i<(len1-len2);i++) { int pos=i; for(j=0;j<len2;j++) { if(s1[...
绛旓細杩欎釜寰幆鐨勬潯浠舵槸!find锛岃〃绀篺ind涓0鐨勬椂鍊欙紙涔熷氨鏄!find涓虹湡锛夎缁х画寰幆銆傚鏋滄槸瑕佸湪find涓0鐨勬椂鍊欓鍑哄惊鐜紝閭e氨寰楁槸for (x = 1; find; x++)浜嗐俧or涓棿鐨勯偅涓娈碉紝鍦ㄦ弧瓒筹紙涓簍rue锛夋椂锛屽惊鐜槸缁х画鐨勩備笉婊¤冻鏃舵墠浼氶鍑哄惊鐜傝繖閲宖ind鍏跺疄搴旇鍙found鈥︹﹁〃绀衡鎵惧埌浜嗏濄備竴寮濮嬫槸娌℃壘鍒帮紝...
绛旓細int find(int *p,int n,int x);璇烽棶涓涓嬶紝浣犺繖鏄嚱鏁板0鏄庡悧锛熷鏋滄槸锛佸氨閿欏湪杩欎簡锛屽0鏄庡嚱 鏁板簲璇ュ湪main鍑芥暟澶栵紒鍦╩ain鍑芥暟澶栧0鏄庡ソ鍟︼紝鍦ㄤ富鍑芥暟閲璋冪敤灏卞彲浠ュ暒锛佽繕鏈夊厛璋冪敤鍚庝娇鐢ㄨ皟鐢ㄥ嚱鏁扮殑杩斿洖鍊硷紒鍦ㄨ皟鐢ㄤ箣鍓嶅厛浼犲弬锛佹敼濡備笅锛乮nclude<stdio.h> int find(int *p,int n,int x);void main()...
绛旓細閫昏緫NOT銆傞昏緫AND銆傞昏緫OR銆備紭鍏堢骇涓猴細NOT AND OR銆傚悓绾ц繍绠椾粠宸﹀埌鍙炽傚湪杩愯涓緭鍏md,杩涘叆dos,杈撳叆cd\杩涘叆C鐩樼殑鐩綍,鐒跺悗杈揹ir灏辨槸c鐩樻枃浠剁殑鍒楄〃. 杈撳叆cd windows杩涘叆windows鏂囦欢澶,杈撳叆tree灏辨槸鐩綍鏍戠殑鎰忔. 杈撳叆D;杩涘叆D鐩樸傛悳绱㈢殑璇濆氨鐢╢ind鍛戒护,鍜寃indows鎼滅储杩欎釜鍔熻兘宸笉澶氥侱ir c:*.exe/b...
绛旓細濡傛灉鏄瓧绗︽暟缁勶紝鍙互浣跨敤strstr鍑芥暟鏌ユ壘鍖归厤銆俿trstr() 鍑芥暟鎼滅储涓涓瓧绗︿覆鍦ㄥ彟涓涓瓧绗︿覆涓殑绗竴娆″嚭鐜般傛壘鍒版墍鎼滅储鐨勫瓧绗︿覆锛屽垯璇ュ嚱鏁拌繑鍥炵涓娆″尮閰嶇殑瀛楃涓茬殑鍦板潃锛涘鏋滄湭鎵惧埌鎵鎼滅储鐨勫瓧绗︿覆锛屽垯杩斿洖NULL銆傚寘鍚枃浠讹細string.h鍑芥暟鍚: strstr鍑芥暟鍘熷瀷锛歟xtern char *strstr(char *str1, const char...
绛旓細1銆Find鍑芥暟瀹氫箟浜嗚繑鍥炵被鍨嬶紝缁撴灉娌℃湁杩斿洖鍊硷紝娌℃湁return璇彞 2銆佽緭鍏ョ粨鏋勪綋鏃讹紝涓嶇敤鍙栧湴鍧绗&锛3銆乵ain鍑芥暟瀹氫箟锛
绛旓細鍙閬嶅巻鏁扮粍 鐒跺悗灏嗘瘡涓厓绱犱笌瑕佹煡璇㈢殑鍊艰繘琛岀浉鍑 鍙栧噺寰楃殑缁濆鍊兼渶灏忕殑閭d釜灏辨槸浜 涓嬮潰鏄竴涓畝鍗曠殑浠g爜 include <stdio.h>#include <stdlib.h>int find(int *a,int n,int x){ int i; int min=abs(*a-x); int r=0; for(i=0;i < n;++i) { if(abs(a[i]...
绛旓細FIND({"A","B","C",...杩炵画涓嶉棿鏂埌 "Z"}...) 杩欎釜鍏紡鏄敤浜庡湪涓涓枃鏈瓧绗︿覆涓煡鎵杩炵画鍑虹幇鐨勫瓧姣嶏紙浠 A 鍒 Z锛夛紝骞惰繑鍥炲畠浠殑浣嶇疆銆傚鏋滀綘瑙夊緱杩欎釜鍏紡姣旇緝绻佺悙锛屽彲浠ヨ冭檻浣跨敤浠ヤ笅绠鍖栫殑鍙欒堪鏂瑰紡锛氬湪涓涓枃鏈瓧绗︿覆涓煡鎵句粠 A 鍒 Z 杩炵画鍑虹幇鐨勫瓧姣嶏紝骞惰繑鍥炲畠浠殑浣嶇疆銆傚彟澶栵紝濡傛灉浣犺...
绛旓細杩欓噷鍐欎簡涓绉嶆柟娉曪紝鏄厛鎵惧埌鏈鍚庝竴涓寚閽堬紝鍙嶅悜鏌ユ壘銆備綘涔熷彲浠ュ厛鎶婂瓧绗︿覆鍙嶈浆锛屽啀鏉ユ煡鎵撅紝绠楁硶涓嶄竴鏍凤紝缁撴灉鐩稿悓銆備笉鎳傚啀闂垜銆俰nclude<stdio.h> int rfind(const char*source ,const char* match);void main(){ /*char *sourcetest = "1230123";char *matchtest = "123";printf("鏌ユ壘鐨勬渶鍚...