查找和替换脚本我使用的 GCMS 程序会在峰面积计数饱和时添加“饱和 (####)”。在我将这些结果从 excel 导出到 JMP 数据表后,我想运行一个脚本来查找这些事件并删除“饱和 ()”,但将数字保留为数字、连续 12,0 格式。
脚本回复:查找和替换脚本我上面给出的代码只是写入JMP日志. 好像@txnelson已经告诉您如何处理“区域”列。 如果您愿意,可以结合使用模式匹配代码和他的 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 );
)
);