Mathematica - StringMatch Elements Within a List? -


i have functions returns cases table match specific strings. once cases match strings, need search each case (which own list) specific strings , command. know how turn whole big list of lists 1 string, , 1 result (when need result each case).

uc@encodetable;   encodetable[id_?personnelq, f___] :=   cases[#,     x_list /;     memberq[x,     s_string /;     stringmatchq[     s, ("*ah*" | "*bh*" | "*gh*" | "*kf*" |        "*mn*"), ignorecase -> true]], {1}] &@    cases[memoizetable["personneltable.txt"], {_, id, __}] 

that function returning cases table

which[(stringmatchq[  tostring@   encodetable[11282], ("*bh*" | "*ah*" |     "*gh*" ), ignorecase -> true]) == true, 1,   (stringmatchq[  tostring@    encodetable[11282], ("*bh*" | "*ah*" |     "*gh*" ), ignorecase -> true]) == false, 0] 

that function supposed return 1 or 0 each case returned first function, don't know how search within lists without making them 1 string , return result each list.

well, probaby want map, it's hard without seeing structure of data operated upon is. perhaps can provide example.

edit: in comment, example result given

dat = {{204424, 11111, sqldatetime[{1989, 4, 4, 0, 0, 0.}], null,  "parthom, mary, mp", null, 4147,  "t-00010 ah bh ui", {"t-00010 ah bh ui", "m-14007 ll gg",   "f-y3710 ah ll ui gg"}, "removed."}, {2040, 11111,  sqldatetime[{1989, 4, 13, 0, 1, 0.}], null, "kevin, stevens, stk",  null, 81238,  "t-00010 ah gh mn", {"t-00010 mn", "m-00100 dd", "p-02320 sd",   "m-14003 ed", "t-y8800 kf", "kj"}}}; 

(actually example had syntax error fixed in hope right way).

now, if define function

func = which[(stringmatchq[#[[8]], ("*bh*" | "*ah*" | "*gh*"),     ignorecase -> true]) == true, 1, true, 0] &; 

(note second condition matched may written true, see documentation of which) this

func[dat[[1]]] (* -> 1 *) 

(note i've changed func have, in order assume wanted do). can applied dat, of elements have form gave, follows:

map[func, dat] 

(* -> {1, 1} *) i'm not sure if want, did best guessing.

edit2: in response comment position of element matched being variable, here 1 way:

clearall[funcel] funcel[p_string] :=    which[stringmatchq[p, ("*bh*" | "*ah*" | "*gh*"),     ignorecase -> true], 1, true, 0]; funcel[___] := 0;  clearall[func]; func[lst_list] := which[memberq[map[funcel, lst], 1], 1, true, 0] 

so

map[func, dat] 

gives {1,1}


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -