【发布时间】:2011-06-30 18:33:08
【问题描述】:
我有一个函数可以从匹配特定字符串的表中返回案例。 一旦我得到与这些字符串匹配的所有案例,我需要在每个案例(这是它自己的列表)中搜索特定字符串并执行哪个命令。但是我所知道的就是将整个列表变成一个字符串,然后我只得到一个结果(当我需要每种情况的结果时)。
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, __}]
该函数正在从表中返回案例
Which[(StringMatchQ[
ToString@
EncodeTable[11282], ("*bh*" | "*ah*" |
"*gh*" ), IgnoreCase -> True]) == True, 1,
(StringMatchQ[
ToString@
EncodeTable[11282], ("*bh*" | "*ah*" |
"*gh*" ), IgnoreCase -> True]) == False, 0]
该函数应该为第一个函数返回的每种情况返回 1 或 0,但我不知道如何在列表中搜索而不将它们全部设为一个字符串并为每个列表返回结果。
【问题讨论】:
标签: list wolfram-mathematica string-matching