English 中文(简体)
无法删除奇怪的窗口行结尾
原标题:cannot remove strange windows line endings

我正将文本从一个窗口的纯文本文件粘贴到一个文本区域。 只有当我手动从文字上删除 CRLF 返回的文字时, 才会在铁路上使用以下的正则文本 :

@scan.raw.scan(/(?<=stamps||[a-z,0-9,A-Z])(.*?)(?=|time)/).each do |body|

我在各种论坛上找到的 用来删除线尾的gsub 留下了一些 混淆了正谱的东西:

(取自模型)

before_create :remove_returns

def remove_returns
  #get rid of pesky carriage returns
  raw.gsub!(/
?/, "")
end

返回行显示为 CRLF, 当我打开在 Notepad++ 中的有关纯文本文件时显示为 CRLF 。

另一个线索:当我调用对象时,轨控台的输出显示直线返回为某种类似制表符的字符,或可能是两个空格,但当我在浏览器中查看显示视图中的对象时,它看起来似乎该字符已被删除,即使正则仍然不起作用。

最佳回答

问题在于我正在用模型中的预设方法去掉线尾, 之后是另一种方法( 也是在_ 创建前), 即依靠删除线尾。 我对控制器进行了操作, 之后是“ 保存 ” 。

def create
@scan = Scan.new(params[:scan])

#eliminate pesky carriage returns
@scan.raw.gsub!(/
?/, "")
@scan.raw.gsub("u000a","")
@scan.raw.gsub!("u000d","")
@scan.raw.gsub!("u0009","")
@scan.raw.gsub!("u000c","")
@scan.raw.gsub!("u0085","")
@scan.raw.gsub!("u2028","")
@scan.raw.gsub!("u2029","")
@scan.raw.gsub!(/0AA/u,"")
@scan.save!
问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签