我有一个NX知识融合检查伴侣程序,以检查是否有任何手动尺寸包含任何类型的数字。
但是维度的数据类型总是字符串列表(我只对列表的第一个位置感兴趣)。
如果包含在列表第一个位置的字符串可以转换为数字类型,即如果字符串是"200“,程序必须返回true并将维度标记附加到列表中,但如果是"22c”,则程序必须返回false。
我尝试了函数MakeNumber( string ),但是只有当字符串可以转换为Number时,这个函数才能工作。如果字符串不是数字,程序就会崩溃。
非常感谢!
我的检查程序函数的dfa代码是:
检验函数
(任何未缓存的) do_check:@{ $dim_manual << mqc_askManualDimensions();
$dim_log <<loop
{
for $each in $dim_manual;
for $is_sleep is mqc_isSleepObject( $each );
for $is_condemned is mqc_isCondemnedObject( $each );
#I print the value i want to check
do ug_printvalue($each);
for $text is mqc_askDimensionManualText( $each );
do ug_printvalue(nth(0,$text));
#I check the type of the dimension content --> String
#If nth(0,$text) is Number type, typecheck returns true
#but always return false because nth(0,$text) is String type!
for $is_number is typecheck(nth(0,$text), Number);
do ug_printvalue($is_number);
do ug_printvalue(TypeName(nth(0,$text)));
#I try to convert the String in a Number. If the String can not be
#converted the program crashes!!
for $n is MakeNumber(nth(0,$text));
do ug_printvalue($n);
#I want to append in the error log only the manual dimensions that
#contains ONLY a number.
if (!$is_sleep & !$is_condemned & $is_number)
append {$each};
};
if !empty?( $dim_log ) Then
@{
$log_msg << @{If (log_msg:="") Then "" Else log_msg:+"~n";} +
mqc_sprintf("Found %s dimension(s) with manual text.", Stringvalue(Length($dim_log)));
ug_mqc_log( nth( log_type:, log_type_option: ), $dim_log, $log_msg );
}
Else donothing;
};发布于 2015-12-02 15:55:58
我找到了解决办法。我的dfa方法,该方法确定是否可以将给定的字符串解析为数字。
( List ) numbers: {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "." , ","};
( Method Boolean) vh_numeric_string:(String $cadena) @{
$is_a_number << loop {
for $text_split is SplitString($cadena,"");
for $i from 1 to Length($text_split);
for $exist_number is Find(nth($i,$text_split),numbers:);
if ($exist_number = NoValue) return False;
return is True;
};
};当在dfa文件的do_check函数中调用此方法时,结果可以存储在循环变量中,如下所示:
for $is_number is vh_numeric_string:(nth(0,$text));发布于 2015-12-01 15:06:34
我编写了一个计算字符串是否为数字的方法。
(List) numbers: {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "." , ","};
(Method Boolean) is_numeric:(String $cadena)
@{
$is_a_number << loop {
for $text_split is SplitString($cadena,"");
do ug_printMessage($text_split);
for $i from 0 to Length($text_split);
for $exist_number is Find(nth($i,$text_split),numbers:);
do ug_printvalue($i);
do ug_printvalue($exist_number);
return is $exist_number != "No Value";
};
};此方法被声明为类的一个属性,只有在数字列表中可以找到$cadena的所有字符(逗号和点已作为可能的十进制分隔符)时,才应该返回true。
但是现在我不知道如何在NX Check mate类中执行这个方法。谢谢。
https://stackoverflow.com/questions/34015854
复制相似问题