Click here to Skip to main content
14,694,918 members
Articles » General Programming » String handling » Text Conversion
Article
Posted 19 Jun 2004

Stats

73.9K views
4.2K downloads
13 bookmarked

Quick code page converter

Rate me:
Please Sign up or sign in to vote.
3.50/5 (13 votes)
19 Jun 2004
A simple tool that converts ANSI string to Unicode using a code page you select.

Introduction

I'll tell you an embarrassing history, after which I've made this utility.

My mother tongue is Russian, and I live in Israel. So that apart from English language, I have Russian and Hebrew installed. In the Windows settings, I set Russian as the default conversion code page from ANSI string. That means that if a non-Unicode program wants to display a string, it is always converted to Unicode using Russian code page.

Once, at evening, I worked on my computer, when suddenly an ICQ popup arrived. It was not displayed correctly (something similar to Chinese :)). That message was from someone I didn't know, with high ICQ#, and indeed longer than 'hello'. Of course, I decided that was some annoying spam, and typed 'f*** off'. Then I had to go out for a couple of hours. When I got back, there was another message waiting for me. It said 'sorry'.

Hm.. I checked the messages history, and discovered that this message arrived from the same user whose message was unreadable. I copied it to another file and opened it with IE, specifying the Hebrew code page. It said:

"Hello, my name is Elad Cohen, I'm a high school student. I found you via ICQ because you're interested in Physics just like me. I've got a couple of question in Mechanics. Would you help me please?"

Utility

It's a very small and simple utility, you'll puzzle out it fast. When you start it, there should appear its icon in the system tray. To convert a string, copy it to the clipboard (if it is in an edit control, then type Ctrl+C), and than double-click the tray icon. Your string should be displayed, whereas at the upper combo box you can choose any code page installed on your system. Enjoy.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

valdok
Software Developer (Senior)
Israel Israel
My name is Vladislav Gelfer, I was born in Kiev (former Soviet Union), since 1993 I live in Israel.
In programming I'm interested mostly in low-level, OOP design, DSP and multimedia.
Besides of the programming I like physics, math, digital photography.

Comments and Discussions

 
QuestionThanks a lot! Pin
alxlabs12-Aug-19 5:41
Memberalxlabs12-Aug-19 5:41 
QuestionGood job; small fix in hChild Pin
Dave Driesen9-Jan-14 10:21
MemberDave Driesen9-Jan-14 10:21 
AnswerRe: Pin
valdok9-Jan-14 10:43
Membervaldok9-Jan-14 10:43 
QuestionFine! Pin
Volynsky Alex8-Jan-14 4:10
professionalVolynsky Alex8-Jan-14 4:10 
GeneralWin7 Pin
voinovv2-Jul-10 10:32
Membervoinovv2-Jul-10 10:32 
QuestionRe: Pin
valdok3-Jul-10 10:10
Membervaldok3-Jul-10 10:10 
GeneralVery Nice Pin
XuShanghua5-Aug-08 0:13
MemberXuShanghua5-Aug-08 0:13 
GeneralZdorovo ! Toda raba ! Spassibo ogromnoe ! est prosba Pin
velikosselski19-Sep-06 12:24
Membervelikosselski19-Sep-06 12:24 
GeneralVery good Pin
Pavlik_Morozov14-Feb-06 2:10
MemberPavlik_Morozov14-Feb-06 2:10 
GeneralSimple and easy. Great job ! Pin
chavdar214-Nov-05 2:25
Memberchavdar214-Nov-05 2:25 
Generalyou can also use this dll in sqlserver Pin
Anonymous23-May-05 2:56
MemberAnonymous23-May-05 2:56 
GeneralNULL Returned Pin
Mike Lucas14-May-05 4:28
MemberMike Lucas14-May-05 4:28 
I'm having a problem when my input parameter is longer than 128 characters. If the input string is over 128 characters, xp_cp2u_web is returning NULL.

I'm created a function so I can call the conversion from a select statement.

Here is the function:

CREATE FUNCTION dbo.FromCodePage(@codePage int, @inputString varchar(2000))
RETURNS nvarchar(2000)
AS
BEGIN
DECLARE @u_value as nvarchar(2000)
DECLARE @outputString varbinary(4000)
DECLARE @convertString as nvarchar(2000)

EXEC master.dbo.xp_cp2u_web @inputString, @outputString OUTPUT, @codePage
SET @convertString = @outputString
-- Now in @convertString you have the unicode translation of @inputString
RETURN @convertString
END

I'm using codepage 1253 (for Greek) and if the inputString is over 126 characters the function returns null.

For example this select works:
SELECT dbo.FromCodePage(1253, 'ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ') AS fixed

This one does not:
SELECT dbo.FromCodePage(1253, 'ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ÐÙÓ ') AS fixed

The only difference is example 1 is 128 characters long and example 2 is 129 characters long.

I'm running the selects from MS SQL Query Analyzer.

Any ideas why?

Thanks,
Michael


GeneralAwesome job! But I found an error in the source code. Pin
ftrbinom,oiunomin29-Oct-04 14:41
Memberftrbinom,oiunomin29-Oct-04 14:41 
GeneralRe: Awesome job! But I found an error in the source code. Pin
valdok30-Oct-04 2:08
Membervaldok30-Oct-04 2:08 
GeneralGreat Pin
Yigal18-Jul-04 2:09
MemberYigal18-Jul-04 2:09 
GeneralGreat Job Pin
joiin21-Jun-04 3:18
Memberjoiin21-Jun-04 3:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.