字串匹配

2021-07-24 19:31:24 字數 1288 閱讀 8975

/找出乙個陣列 

nsfilemanager *filemanager = [nsfilemanager defaultmanager];

nsstring *defaultpath = [[nsbundle mainbundle] resourcepath];

nserror *error;

nsarray *directorycontents = [filemanager contentsofdirectoryatpath:defaultpath error:&error]

//匹配字串,反回結果, self==表示陣列中每乙個元素

nsstring *match = @"imagexyz-999.png";

nspredicate *predicate = [nspredicate predicatewithformat:@"self == %@", match];

nsarray *results = [directorycontents filteredarrayusingpredicate:predicate];

//近似匹配字串,類似sql中的語法

nsstring *match = @"imagexyz*.png";

nspredicate *predicate = [nspredicate predicatewithformat:@"self like %@", match];

nsarray *results = [directorycontents filteredarrayusingpredicate:predicate];

//不區分大小寫匹配

nsstring *match = @"imagexyz*.png";

nspredicate *predicate = [nspredicate predicatewithformat:@"self like[cd] %@", match];

nsarray *results = [directorycontents filteredarrayusingpredicate:predicate];

//正則匹配

nsstring *match = @"imagexyz-//d//.png";

nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@", match];

nsarray *results = [directorycontents filteredarrayusingpredicate:predicate];

字串匹配

題目描述 讀入資料string 然後讀入乙個短字串。要求查詢string 中和短字串的所有匹配,輸出行號 匹配字串。匹配時不區分大小寫,並且可以有乙個用中括號表示的模式匹配。如 aa 123 bb 就是說aa1bb aa2bb aa3bb都算匹配。輸入 輸入有多組資料。每組資料第一行輸入n 1 n ...

字串匹配

time limit 1000ms memory limit 65536k 給定兩個字串string1和string2,判斷string2是否為string1的子串。輸入包含多組資料,每組測試資料報含兩行,第一行代表string1,第二行代表string2,string1和string2中保證不出現...

字串匹配

面試題 給一串很長的字串,要求找到符合要求的字串,例如目的串 123 1 3 2 12 3 這些都要找出來 思路一 利用兩層迴圈,逐個查詢目的串中的字元,比如先查詢字元 1 是否在長字串中,再查詢 2 是否在長字串中,直到目的串遇到 0 是 include include include int m...