幫助了解 if else 中包含的內容你好,
我編寫了以下代碼,用於檢查列表是否包含字符並相應地執行一些步驟。
由於某種原因,腳本不檢查“if contains”條件並始終執行 else 部分。我認為我在這裡犯了一個愚蠢的錯誤。
Clear Symbols();
Delete Symbols();
clear globals();
dtNext = Open("C:\temp\output.csv","invisible");
Summarize(dtNext, testlist = By(:test));
show(testlist );
SAVEPATH = "C:\temp\";
If(contains(testlist ,"M"),
Macrodt=New Table("test_type",
New Column("test_type",
Character,
Nominal,
Set Values( {"Morning"})
),
invisible
);
, //else
Macrodt=New Table("test_type",
New Column("test_type",
Character,
Nominal,
Set Values( {"Evening"})
),
invisible
);
);
//Save macro file
Macrodt<<SAVE></SAVE>
回复:有關 if else 中包含的幫助我使用了 cocncatitems 函數並且它有效。
謝謝
回复:有關 if else 中包含的幫助作為@傑夫·珀金森建議,更多信息會有所幫助,但我會嘗試一下我認為可能會讓您感到困惑的根源。 “Contains”函數可用於列表或字符串...如果您正在查找任何列表項是否包含特定字符,您的“If”語句將不會產生所編寫的所需結果。 如果這是您的意圖,您可以在“If”語句中使用 Concat Items 函數包圍“testlist”變量,即 Concat Items(testlist) 計算結果為由縫合在一起的所有列表項組成的單個字符串。 現在,當查找新字符串中存在的特定字符時,Contains 函數將返回肯定響應。
希望這可以幫助。
回复:有關 if else 中包含的幫助您的代碼中沒有明顯的錯誤。 我們需要更多細節來幫助找出混亂所在。
這是一個示例,表明您的原型是正確的。
dts = {"$SAMPLE_DATA\Fitness.jmp", "$SAMPLE_DATA\Big Class.jmp"};
For( i = 1, i <= N Items( dts ), i++,
dtNext = Open( dts[i] );
Summarize( dtNext, testlist = By( :age ) );
Show( testlist );
If( Contains( testlist, "42" ),
Show( "testlist contains 42" );
, //else
Show( "testlist doesn't contain 42" )
);
);
日誌:
/*:
testlist = {"38", "40", "42", "43", "44", "45", "47", "48", "49", "50", "51", "52", "54", "57"};
"testlist contains 42";
testlist = {"12", "13", "14", "15", "16", "17"};
"testlist doesn't contain 42";