我有一个主题标题包含在“|”中的文档 人物。
例如“|链接|”
我想检查字符串是否以“|”开头和结尾 用于验证特定文档的主题标题是否有效的字符。我该怎么做?
来源:
@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