Project1

标题: 如何判断某个文本文档第一行的内容? [打印本页]

作者: 张咚咚    时间: 2013-9-3 05:46
标题: 如何判断某个文本文档第一行的内容?
如何判断某个文本文档的第一行内容写的是什么啊,求大神!
作者: 铃仙·优昙华院·因幡    时间: 2013-9-3 12:51
RUBY 代码复制
  1. a = []
  2.  
  3. File.open( "2.txt", "r" ) do |fp|
  4.   a = fp.readlines
  5. end
  6.  
  7. p a[0]

作者: 张咚咚    时间: 2013-9-3 17:19
铃仙·优昙华院·因幡 发表于 2013-9-3 12:51
a = []

File.open( "2.txt", "r" ) do |fp|

十分感谢!但是怎么调用到条件分歧上呢,求指点一下!
作者: 铃仙·优昙华院·因幡    时间: 2013-9-3 18:17
RUBY 代码复制
  1. def fileLine?(file_name, content)
  2.     file_one = 0
  3.     File.open( file_name, "r" ) do |fp|
  4.       file_one = fp.readlines[0]
  5.    end
  6.    return file_one == content
  7. end



丢到脚本空白页里去. 使用的时候 条件分歧->脚本-> fileLine?( 文件名, 需要对比的内容)
作者: 张咚咚    时间: 2013-9-3 19:49
标题: 暂时命名
太谢谢你啦!




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1