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!

On Mon, Jan 13, 2014 at 10:50 AM, Dan F. [email protected] 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).

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

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

Strange - when I use IRB - I get this:

2.0.0-p247 :001 > line = “hellothere" => "hellothere”
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:inblock in ’
from superscrubber.rb:171:in each' from superscrubber.rb:171:in

Dan:

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

Read this very enlightening blog entry on your problem:

Wayne