Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有变量的Groovy标记器_Groovy - Fatal编程技术网

带有变量的Groovy标记器

带有变量的Groovy标记器,groovy,Groovy,在用于soapui的groovy脚本中 我有一个循环,我试图用一个变量定义两个变量,但我不知道语法是什么: 在我的源文件liste.txt中,我必须为每个文本行设置字段(id和日期),用-,如下所示: 0D011A2571D4E6FDF290-2021 0D099Z2571D4E6FDF290-2020 //locate the source file File file1 = new File("C:/User/liste.txt") List textLine = file1.readLi

在用于soapui的groovy脚本中 我有一个循环,我试图用一个变量定义两个变量,但我不知道语法是什么:

在我的源文件liste.txt中,我必须为每个文本行设置字段(id和日期),用-,如下所示: 0D011A2571D4E6FDF290-2021

0D099Z2571D4E6FDF290-2020

//locate the source file
File file1 = new File("C:/User/liste.txt") 
List textLine = file1.readLines() 
def (id, date) = textLine.tokenize( '-' ) //it doesn't work here !
如果我手动写入字符串文本行

def (id, date) = '0D099Z2571D4E6FDF290-2020'.tokenize( '-' ) 
它起作用了,结果是:

id=0D099Z2571D4E6FDF290

日期=2020年

我尝试了很多语法,但每次都有问题。。。 如何在标记器中写入变量textLine?或者有没有更简单的方法来定义n个变量和1个变量

非常感谢

类似于:

new File("C:/User/liste.txt").splitEachLine( '-' ){ 
  if( 2 != it.size() ) return // bail out
  def (id, date) = it
  doSmthWith( id, date )
}

最后,我继续搜索并找到另一个技巧,我做到了:

File file1 = new File("C:/User/liste.txt") 
List textLine = file1.readLines() //read toutes les lignes

def Line = textLine.pop() //take the last line

def id = Line [0..19] //split 19 first characteres from Line

def date = Line [21..24] //split characteres from 21 to 24 from Line
结果:

当前线路:0D010710C9D4DBC8675B-2024

id=0D010710C9D4DBC8675B

日期=2024年

希望这能帮助一些人


感谢injecter您的帮助感谢您的快速回复,我尝试了,但出现了以下错误:groovy.lang.MissingMethodException:没有方法签名:Script84.doSmthWith()适用于参数类型:(java.lang.String,java.lang.String)值:[0D011A2571D4E6FDF2902021]第5行错误
doSmthWith()
应该是您的方法或代码。我只是把它作为一个例子)是的,你说得对,在我理解之后,我写了这个:static main(args){new File(“C:/User/liste.txt”).splitEachLine('-'){if(2!=it.size())return//bail out def(id,date)=it def(id,date it.tokenize('-')}}log.info“id=”id=“+id log.info”date+date//end但它现在返回:Groovy.lang.MissingPropertyException:没有这样的属性:class:Script121的id错误在第5行出现了什么问题?谢谢