Splitting on a backtick

Hi everyone. I am trying to process a text file in which someone used a
backtick ( ` ) to separate fields of each line. I can't seem to
"escape" the backtick in my code when trying to use the split()
functionality (want to split the line of text using the backtick as a
separator).

Any advice? Thanks!

···

--
Posted via http://www.ruby-forum.com/.

2.1.0 (main):0 > "foo`bar`baz"
=> "foo`bar`baz"
2.1.0 (main):0 > "foo`bar`baz".split /`/
=> [
  [0] "foo",
  [1] "bar",
  [2] "baz"
]
2.1.0 (main):0 >

Do you have a test case that demonstrates this not working?

···

On Mon, Jan 13, 2014 at 10:50 AM, Dan F. <lists@ruby-forum.com> wrote:

Hi everyone. I am trying to process a text file in which someone used a
backtick ( ` ) to separate fields of each line. I can't seem to
"escape" the backtick in my code when trying to use the split()
functionality (want to split the line of text using the backtick as a
separator).

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Strange - when I use IRB - I get this:

2.0.0-p247 :001 > line = "hello`there"
=> "hello`there"
2.0.0-p247 :002 > line.split('`')
=> ["hello", "there"]
2.0.0-p247 :003 > line.split /`/
=> ["hello", "there"]

But in my script, if I do this:

lineparts = line.split /`/

or this:

lineparts = line.split('`')

when I run it, I get this error:

superscrubber.rb:172:in `split': invalid byte sequence in UTF-8
(ArgumentError)
  from superscrubber.rb:172:in `block in <main>'
  from superscrubber.rb:171:in `each'
  from superscrubber.rb:171:in `<main>'

···

--
Posted via http://www.ruby-forum.com/.

Dan:

It's not a backtick problem, it's your source.

Read this very enlightening blog entry on your problem: http://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences

Wayne

···

________________________________