Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3217234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:23:14+00:00 2026-05-17T15:23:14+00:00

We have different types of hyphens/dashes (in some text) populated in db. Before comparing

  • 0

We have different types of hyphens/dashes (in some text) populated in db. Before comparing them with some user input text, i have to normalize any type of dashes/hyphens to simple hyphen/minus (ascii 45).

The possible dashes we have to convert are:

Minus(−) U+2212 − or − or −
Hyphen-minus(-) U+002D -
Hyphen(-) U+2010
Soft Hyphen   U+00AD  ­
Non-breaking hyphen  U+2011  &#8209
Figure dash(‒)  U+2012 (8210) ‒ or ‒
En dash(–) U+2013 (8211) –, – or –
Em dash(—) U+2014 (8212) —, — or —
Horizontal bar(―) U+2015 (8213) ― or ―

These all have to be converted to Hyphen-minus(-) using gsub.
I’ve used CharDet gem to detect the character encoding type of the fetched string. It’s showing windows-1252. I’ve tried Iconv to convert the encoding to ascii. But it’s throwing an exception Iconv::IllegalSequence.

ruby -v => ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.8.0]
rails -v => Rails 2.3.5
mysql encoding => ‘latin1’

Any idea how to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:23:15+00:00Added an answer on May 17, 2026 at 3:23 pm

    Caveat: I know nothing about Ruby, but you have problems that are nothing to do with the programming language that you are using.

    You don’t need to convert Hyphen-minus(-) U+002D - to simple hyphen/minus (ascii 45); they’re the same thing.

    You believe that the database encoding is latin1. The statement "My data is encoded in ISO-8859-1 aka latin1" is up there with "The check is in the mail" and "Of course I’ll still love you in the morning". All it tells you is that it is a single-byte-per-character encoding.

    Presuming that "fetched string" means "byte string extracted from the database", chardet is very likely quite right in reporting windows-1252 aka cp1252 — however this may be by accident as chardet sometimes seems to report that as a default when it has exhausted other possibilities.

    (a) These Unicode characters cannot be decoded into latin1 or cp1252 or ascii:

    Minus(−) U+2212 − or − or −
    Hyphen(-) U+2010
    Non-breaking hyphen  U+2011  &#8209
    Figure dash(‒)  U+2012 (8210) ‒ or ‒
    Horizontal bar(―) U+2015 (8213) ― or ―
    

    What gives you the impression that they may possibly appear in the input or in the database?

    (b) These Unicode characters can be decoded into cp1252 but not latin1 or ascii:

    En dash(–) U+2013 (8211) –, – or –
    Em dash(—) U+2014 (8212) —, — or —
    

    These (most likely the EN DASH) are what you really need to convert to an ascii hyphen/dash. What was in the string that chardet reported as windows-1252?

    (c) This can be decoded into cp1252 and latin1 but not ascii:

    Soft Hyphen   U+00AD  ­
    

    If a string contains non-ASCII characters, any attempt (using iconv or any other method) to convert it to ascii will fail, unless you use some kind of "ignore" or "replace with ?" option. Why are you trying to do that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.