Thursday, February 25, 2010

Commas and catastrophes

In the letters I get e-mailed for publication, for some reason some of them have all their apostrophes replaced with commas, in some text conversion error along the way. I'm not sure where or how it happens. Here's a sample from a recent letter:

"There‚s nothing that says we can‚t... If you‚re willing, I‚m able."

Now, if I do a straight find/replace, all the commas are replaced too!
OK, I can replace ,s with 's, ,m with 'm, and so on. This works because there's no space after the commas/apostrophes. But it makes for tedious work.

I found a way, though: first I replace all the actual commas, including the space after it! with a random string, like +++. Then I replace all the fake commas with apostrophes. And then I replace +++ with comma-space. Dom-dimmi-done.

5 comments:

Pascal [P-04referent] said...

Heh. I use clever practical ideas like this all the time.

Except I tend to use "XXX" instead of "+++".
Which reveals how rarely I have to edit porn-related texts!

For these, I use "ZZZ" instead. Because there are very few occasions where my texts deal simultaneously with porn and sleep.

Then again...

(U_U)

Alex said...

Just run a Sed script, or Awk.

dave nielsen said...

Just run a Sed script, or Awk.

I have no idea what that means. Hopefully Eolake does. :)

Eolake Stobblehouse said...

Not a friggin clue.

Alex said...

AWK

SED

these are great tools for the sort of repeated search and replace that you are talking about. Unfortunately I haven't used them in about 4 years and have forgotten the syntax.

If you are using an editor which allows regular expressions you can search for something like
",[^ ^\t]" to match for commas not followed by spaces or tabs.