Solved

Converting unicode punctuation to ASCII

Posted on 2008-06-19
8
1,274 Views
Last Modified: 2012-06-22
Hi,

I am reading in some text from a file. The text was saved (as tab-delimited text) from Excel, but may have originally been copied into Excel from Word. As a result of this (I assume) the text has characters such as the 'left single quotation mark' 8216 rather than the ASCII equivalent single quote. Another example is unicode 8230, which is the ellipsis (...) character which Exel seems to insert for some reason. I would like to convert any such characters into the ASCII equivalent. I understand not all incode characters have an ASCII equivalents, and those I will simple filter out, but does anyone know of a definitive list / table of which characters I can convert ? Java code would be even better of course. Thanks in advance.

0
Comment
Question by:emsttam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821452
>>Java code would be even better of course

.. and yet it's been posted in the C# TA? I *can* give you a Java answer if that's really what you want
0
 

Author Comment

by:emsttam
ID: 21821488
CEHJ,

The Java bit was optional. The question asked for a list / table.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821543
OK. I'm not sure if there's a list available - replacements would be subjective and differ among locales. Given access to the original Unicode string, you could do something like the following for the characters you mention:


s = s.replaceAll("\u2018", "'");
s = s.replaceAll("\u2019", "'");
s = s.replaceAll("\u2026", "");

Open in new window

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:emsttam
ID: 21821759
CEHJ:

Sorry, perhaps I wasn't clear. It's not the coding that's the difficulty, it's getting a definitive list of which unicode characters to look out for which can be converted into an ASCII equivalent (such as the examples in the question).
0
 
LVL 13

Accepted Solution

by:
MicheleMarcon earned 500 total points
ID: 21822035
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21822117
>>it's getting a definitive list of which unicode characters to look out for which can be converted into an ASCII equivalent

As i mentioned, such things are subjective: do you want to delete ellipses or replace them with three dots? Do you want to replace the left quote with a backtick or a normal single quote? Only you know
0
 

Author Closing Comment

by:emsttam
ID: 31468735
Well that's certainly complete :)
I'll extract the most likely candidates from that page, the punctuation in particular. Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21822213
I'm confused emsttam. It would appear from your chosen answer that the question was really 'can you show me a table of Unicode character codes?' If so, the definitive ones are here:

http://www.unicode.org/charts/
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question