gpt4 book ai didi

ruby start_with?(), end_with?()

转载 作者:数据小太阳 更新时间:2023-10-29 07:40:23 32 4
gpt4 key购买 nike

我有一个主题标题被包含在“|”中的文档字符。

例如“|链接|”

我想检查字符串是否以“|”开头和结尾字符来验证特定文档的主题标题是否有效。我该怎么做?

来源:

@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

最佳答案

你试过RDoc了吗? ?

"| LINKS |".start_with?("|") # => true
"| LINKS |".end_with?("|") # => true

关于 ruby start_with?(), end_with?(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6394707/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com