EDA365电子工程师网

标题: 对着练习自己写了一个测试,发现没输出,请大大们帮忙看一下!! [打印本页]

作者: ghfghyb    时间: 2012-7-18 21:36
标题: 对着练习自己写了一个测试,发现没输出,请大大们帮忙看一下!!
lStr = list(" Power TOP *(7710.00 -1865.00) to *(6705.00 -1615.00)" "GND BOTTOM *(7890.00 -1774.00) to *(6575.00 -2045.00)")
rexCompile( "^[A-Z0-p_]+[ ]+[A-Z0-9-]+[ ]+([-0-9.]+[-0-9.])+[A-Z]+([-0-9.]+[-0-9.])")
; \\(...\\) 结构表示匹配的部分将可以用19提取出来
; [A-Z]表示匹配A~Z的字符,+表示至少有一个这样的字符
foreach( item lStr
  when( rexExecute( item )
      str1 = rexSubstitute( "^[1]" )
      str2 = rexSubstitute( "^[2]" )
      str3 = rexSubstitute( "^[3]" )
          str4 = rexSubstitute( "^[4]" )
          str5 = rexSubstitute( "^[5]" )
          str6 = rexSubstitute( "^[6]" )
        printf("%s<->%s<->%s<->%s<->%s<->%s\n" str1 str2 str3 str4 str5 str6)
  )
);
作者: XYX365    时间: 2012-7-19 13:47
上面看起來有點複雜,可以改用下列看看,是不是你要的結果
lStr = list("Power TOP *(7710.00 -1865.00) to *(6705.00 -1615.00)" "GND BOTTOM *(7890.00 -1774.00) to *(6575.00 -2045.00)")
foreach( item lStr
  tTemp = parseString(item " *()")
  str1 = nthelem(1 tTemp)
  str2 = nthelem(2 tTemp)
  str3 = nthelem(3 tTemp)
  str4 = nthelem(4 tTemp)
  str5 = nthelem(6 tTemp)
  str6 = nthelem(7 tTemp)
  printf("%s<->%s<->%s<->%s<->%s<->%s\n" str1 str2 str3 str4 str5 str6)
)
作者: XYX365    时间: 2012-7-19 15:25
本帖最后由 XYX365 于 2012-7-20 14:58 编辑

還有一種方法
lStr = list("Power TOP *(7710.00 -1865.00) to *(6705.00 -1615.00)" "GND BOTTOM *(7890.00 -1774.00) to *(6575.00 -2045.00)")
rexCompile("\\([A-Za-z]*\\)[ ]+\\([A-Za-z]*\\)[ *(]+\\([-?0-9.]*\\)[ ]+\\([-?0-9.]*\\)[) to*(]+\\([-?0-9.]*\\)[ ]+\\([-?0-9.]*\\)")
或是改為rexCompile("\\([A-Za-z]*\\) \\([A-Za-z]*\\)[ *(]+\\([0-9.-]*\\) \\([0-9.-]*\\)[) to*]+(\\([0-9.-]*\\) \\([0-9.-]*\\)")也可以


foreach( item lStr
  when( rexExecute( item )
      str1 = rexSubstitute("\\1")
      str2 = rexSubstitute("\\2" )
      str3 = rexSubstitute("\\3" )
      str4 = rexSubstitute("\\4" )
      str5 = rexSubstitute("\\5" )
      str6 = rexSubstitute("\\6" )
      printf("%s<->%s<->%s<->%s<->%s<->%s\n" str1 str2 str3 str4 str5 str6)
  )
);
作者: ghfghyb    时间: 2012-7-19 20:58
XYX365 3# 发表于 5 小时前

请教一个问题,,parseString,,nthelem,,这两个代码是实现什么功能啊!!
作者: ghfghyb    时间: 2012-7-19 21:01
看了一下资料了,,明白什么意思,,看样子,还是基础太差了,,我还是从资料开始看吧!!

Selecting an Indexed Element from a List (nthelem)
nthelem returns an indexed element of a list, assuming a one-based index. Thus
nthelem(1 l_list) is the same as car(l_list).
nthelem( 1 '( a b c ) ) => a
z = '( 1 2 3 )
nthelem( 2 z ) => 2
作者: xipanlong    时间: 2012-7-19 22:32
学习了,看来我也要基础学习了
作者: szhot    时间: 2012-7-20 00:07
akndk




欢迎光临 EDA365电子工程师网 (https://bbs.elecnest.cn/) Powered by Discuz! X3.2