查找和替換腳本我使用一個GCMS程序,當峰面積計數達到飽和時,它會添加“飽和(####)”。在將這些結果從excel導出到JMP數據表後,我想運行一個腳本來查找這些出現並刪除“ saturated()”,但將數字保留為連續的數字12,0格式。
腳本編寫回复:查找和替換腳本以交互方式,使用“查找”功能對“(”和“)”進行全局替換非常容易。然後,使用“標準化屬性”,可以選擇所有有問題的列,並將它們更改為數字,連續,格式(固定的12月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 );
)
);回复:查找和替換腳本謝謝您的腳本,但看來我不夠具體。編寫腳本對我來說是很新的,我認為數字的長度無關緊要。我猜這是錯誤的。我使用了該腳本,但無法將“ saturated(635403558)”轉換為635403558。我感謝您的幫助。
回复:查找和替換腳本腳本期望“(”是第一個字符,而“)”是最後一個字符。空白字符是否可能在開頭或結尾?
試試這個版本的腳本,看看是否有幫助
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 );
)
);回复:查找和替換腳本如果我理解正確,這可能是一個使用機會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();
// 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 );