ruby start_with?(),end_with?()
||
我有一个主题标头用\“ | \”字符括起来的文档。
例如。 \“ |链接| \”
我想检查字符串是否以\“ | \”字符开头和结尾,以验证特定文档的主题标头是否有效。我该怎么做?
资源:
@filetarget = \" < document file location here > \"
@line = \"\"
file = File.new(@filetarget)
while (@line = file.gets)
if((@line.start_with?(\"|\")) and (@line.end_with?(\"|\")))
puts \"Putting: \" + @line
end
end
用于解析的文档文字:
| LINKS |
http://www.extremeprogramming.org/ <1>
http://c2.com/cgi/wiki?ExtremeProgramming <2>
http://xprogramming.com/index.php <3>
| COMMENTS |
* Test comment
* Test comment 2
* Test comment 3
没有找到相关结果
已邀请:
2 个回复
bab
这样,您可以验证其他内容,例如标头必须全部为大写且在其周围需要空格(
)。
阀傻