Ruby on rails Ruby如何检测字符串中的回车?

Ruby on rails Ruby如何检测字符串中的回车?,ruby-on-rails,ruby,string,carriage-return,Ruby On Rails,Ruby,String,Carriage Return,我正在遍历一个包含多个回车的大字符串。我希望我的逻辑在每次发现回车时都能做些什么(在回车之前创建一个包含所有字符串内容的新ActiveRecord实例) 看 如果只想传递上一换行之后的字符串部分,请更改该行: action str[0..i-1] 致: 你能展示一下到目前为止你做了什么吗?你在找吗?我也不知道这个。我不知道Rails,所以我刚刚把字符串传递给了方法action。我假设创建ActiveRecord实例很简单。 doit("Three blind mice,\nsee how t

我正在遍历一个包含多个回车的大字符串。我希望我的逻辑在每次发现回车时都能做些什么(在回车之前创建一个包含所有字符串内容的新ActiveRecord实例)

如果只想传递上一换行之后的字符串部分,请更改该行:

action str[0..i-1]
致:


你能展示一下到目前为止你做了什么吗?你在找吗?我也不知道这个。我不知道Rails,所以我刚刚把字符串传递给了方法
action
。我假设创建
ActiveRecord
实例很简单。
doit("Three blind mice,\nsee how they run.\nThey all ran after the farmer's wife\n")
  # This is what I've read: Three blind mice,
  # This is what I've read: Three blind mice,
  # see how they run.
  # This is what I've read: Three blind mice,
  # see how they run.
  # They all ran after the farmer's wife
action str[0..i-1]
action str[start_idx..i-1]