查找和替換的腳本我使用 GCMS 程序,當峰面積計數飽和時,該程序會添加“飽和 (####)”。將這些結果從 Excel 導出到 JMP 數據表後,我想運行一個腳本來查找這些事件並刪除“飽和 ()”,但保留數字、連續 12,0 格式。
大規模定制分享和交流結果回复:查找和替換的腳本我上面給出的代碼只是寫入JMP 日誌。 好像@tx尼爾森已經告訴您如何處理“區域”列。 如果您願意,您可以結合使用模式匹配代碼和他的 JSL。
有了所有這些事情,就可以歸結為您可以安全地假設輸入的規律性。 雖然模式匹配方法(稍微)更通用(並且可以很容易地變得更通用),但在您的情況下,這可能並不重要。
回复:查找和替換的腳本在您的“區域”列上嘗試此操作
Names Default To Here( 1 );
dt = Current Data Table();
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( k = 1, k <= N Rows( dt ), k++,
If( Contains( :Area[k], "(" ),
:Area[k] = Word( 2, :Area[k], "()" )
)
);
:Area << data type( numeric ) << modeling type( continuous ) << Format( "Fixed Dec", 12, 0 );回复:查找和替換的腳本遺憾的是,當我運行腳本時什麼也沒發生。我附上了數據的屏幕截圖以及列屬性(如果有幫助的話)。再次感謝!

回复:查找和替換的腳本如果我理解正確的話,這可能是一個使用的機會JMP的模式匹配(謝謝@Craige_Hales 


NamesDefaultToHere(1);
// Define a function
removeSaturated =
Function({inStr}, {Default Local},
// A pattern that will match a span of digits, with or without a leading '-'
digits = (""|"-") + patSpan("0123456789");
// Put the match into 'found' (might be identical to 'inStr')
patMatch(inStr, digits >? found);
// Return 'found' as a number
Num(found);
);
// Try it out
Print(removeSaturated("saturated( 635403558 )"));
Print(removeSaturated("saturated(635403558)"));
Print(removeSaturated("635403558"));
Print(removeSaturated("635403"));
Print(removeSaturated("-635403"));
Print(removeSaturated("saturated( -635403 )"));
回复:查找和替換的腳本該腳本期望“(”為第一個字符,“)”為最後一個字符。開頭或結尾可能有空白字符嗎?
嘗試這個版本的腳本,看看是否有幫助
Names Default To Here( 1 );
dt = Current Data Table();
// Get all character columns
colList = dt << get column names( character, string );
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( I = 1, i <= N Items( colList ), i++,
If( Left( Trim( Char( Column( dt, colList[i] )[1] ) ), 1 ) == "(" & Right( Trim( Char( Column( dt, colList[i] )[1] ) ), 1 ) == ")",
For( k = 1, k <= N Rows( dt ), k++,
If( Left( (Trim( Column( dt, colLIst[i] ) )[k]), 1 ) == "(",
Column( dt, colList[i] )[k] = Substr( Trim( Column( dt, colList[i] )[k] ), 2 )
);
If( Right( Trim( Column( dt, colList[i] )[k] ), 1 ) == ")",
Column( dt, colList[i] )[k] = Word( 1, Column( dt, colList[i] )[k], ")" )
);
);
// Convert to numeric, etc.
Column( dt, colList[i] ) << data type( numeric ) << modeling type( continuous ) << Format( "Fixed Dec", 12, 0 );
)
);回复:查找和替換的腳本謝謝你的劇本,但看來我不夠具體。編寫腳本對我來說是非常新的,我認為數字的長度並不重要。我猜這是錯誤的。我嘗試了該腳本,但無法將“飽和(635403558)”變成635403558。我感謝您的幫助。
回复:查找和替換的腳本以交互方式,使用“查找”功能來全局替換“(”和“)”非常容易。然後,使用標準化屬性,您可以選擇所有有問題的列,並將它們更改為數字、連續、格式(Fixed Dec, 12,0)
查找可在
編輯=>搜索=>查找
如果數據表位於左側列面板的紅色三角形下方,則可以使用標準化屬性。
這是一個小腳本,也可以實現這一點,但是對於大型數據表,它可能會很慢
Names Default To Here( 1 );
dt = Current Data Table();
// Get all character columns
colList = dt << get column names( character, string );
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( I = 3, i <= N Items( colList ), i++,
If( Left( char(Column( dt, colList[i] )[1]), 1 ) == "(" & Right( char(Column( dt, colList[i] )[1]), 1 ) == ")",
For( k = 1, k <= N Rows( dt ), k++,
If( Left( (Column( dt, colLIst[i] )[k]), 1 ) == "(",
Column( dt, colList[i] )[k] = Substr( Column( dt, colList[i] )[k] ,
2)
);
If( Right( (Column( dt, colList[i] )[k]), 1 ) == ")",
Column( dt, colList[i] )[k] = Word( 1, Column( dt, colList[i] )[k], ")" )
);
);
// Convert to numeric, etc.
Column( dt, colList[i] ) << data type( numeric ) << modeling type( continuous ) <<
Format( "Fixed Dec", 12, 0 );
)
);