Question

Convert Unicode file to "normal" file.

Asked by: DFlaschen

I have written a program in Visual C++ that needs to process a Unicode file.  I know zero about Unicode.  

The file is attached.  (As a side note: One of my editors reads the file in as garbage by default.  If I specify "Unicode - Little Endian" the editor displys the file normally.)  So, I guess the format must be Unicode - Little Endian (whatever that means).

I know that C++ has commands to process such Unicode files (_wfopen, wcscpy, etc.) but I found those commands difficult

Does anyone know of a command line utility (or freeware program) that will convert my file to normal ASCII?
I Googled one reference:  "TYPE unicodeFile.txt > AsciiFile.txt".  But it didn't work.
I am using XP Pro.

Thanks.

  • Norton-Ghost.log.txt
    • 98 KB

    Here is an example of this Unicode file - that I am having trouble parsing.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-05-25 at 17:32:39ID23431795
Topics

Scripting Languages

,

MS DOS

,

C++ Programming Language

Participating Experts
4
Points
125
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. unicodes
    What are the API function to convert from unicode to ASCII code and from ASCII code back to unicode. If there is not such API, can you show me how to do this? Pts will be increased for good ans. Thanks
  2. Unicode to ASCII conversion
    I am trying to program a command-line utility that will convert a file from Unicode to ASCII. Files are approx 60 MB. I have the command line architecture built, I just can't figure out how to read the unicode file, convert it to ascii and write it back out. Any help would be...
  3. Ascii to unicode
    <script type="text/javascript"> Function ascii2unicode(text) { unicode= text return unicode } </script> =) i want to convert the text to \u???? characters. (A points) if thats possible. or replace any characters > 127 to "?"(B points) - ...
  4. Convert Unicode into Ascii
    I have values that are in Unicode. Is there a straight forward way to convert this to Ascii? TIA.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: evilrixPosted on 2008-05-25 at 17:45:41ID: 21644137

What you refer to as Unicode is actually a UTF encoded file. Unicode is a 32 bit character set, each character is called a code-point. Code-points are generally encoded using a Unicode Transformation Format (UTF). There are 3 main formats, UTF8, UTF16 and UTF32. UTF8 uses 8 bit bytes to encode as a multi-byte sequence, UTF16 uses 16 bit words to encode as a multi-byte sequence, and UTF32 uses 32 bit dword to encode as a fixed-byte sequence. When referring to Unicode we generally talk about narrow (normally 8 bit bytes) or wide. On Windows wide is 16 bits so the native encoding for Windows if UTF16, whereas on Linux wide is 32 bits. Narrow is generally represented by the type 'char' and wide is represented by the type 'wchar_t'.

http://en.wikipedia.org/wiki/UTF-8
http://en.wikipedia.org/wiki/UTF-16
http://en.wikipedia.org/wiki/UTF-32

You can convert UTF16 (wide) to UTF8 (Narrow, of which ASCII is a subset of) quite simply in C++ using wcstombs.
http://www.cplusplus.com/reference/clibrary/cstdlib/wcstombs.html

>> If I specify "Unicode - Little Endian" the editor displys the file normally.
This is because UTF(Unicode Transformation Format)'s are multiple bytes and there can come in different orders, big endian or little endian. If the file has a Byte Order Mark (BOM) a text editor can figure our the endianess automatically, otherwise you'll have to tell it.
http://en.wikipedia.org/wiki/Byte_Order_Mark


 

by: evilrixPosted on 2008-05-25 at 17:58:43ID: 21644186

ooh, I forgot to give you this link which explains endianess...

http://en.wikipedia.org/wiki/Endianness

...basically, it just denotes which way around the bytes are ordered in data types that are compound bytes.

So, imagine we have UTF16, the 16 bit word is made up of 2 bytes, let's call them H for high order and L for low order. This is how they would be ordered depending upon their endianess...

Address         0 1  2 3  4 5  6 7
---------------------------------------
Big Endian:    [H|L][H|L][H|L][H|L]
Little Endian: [L|H][L|H][L|H][L|H]

                                              
1:
2:
3:
4:

Select allOpen in new window

 

by: evilrixPosted on 2008-05-25 at 18:49:09ID: 21644289

>> Does anyone know of a command line utility (or freeware program) that will convert my file to normal ASCII?
It's a bit quite and dirtly, but try compiling the code below. It takes standard in as a wide stream and write to standard out as a narrow stream.

Assume you call it conv.exe, you use it like this...
'type utf16.txt | conv.exe  > utf8.txt'

type is a DOS command that will stream a file through the standard input of a program and > is an operator that will take the standard output of a program and redirect it to a file. In this case the input file is called utf16.txt and the output file is called utf8.txt. I can't promise this'll work with any fancy languages like Chinese but it seemed to work fine with English saved as UTF16 and then converted back. Also, there is no error handling, I leave that to you to implement as you see fit.

I hope this helps.

-Rx.

#include <iostream>
 
int main()
{
	wchar_t wc = 0;;
	while(!std::wcin.get(wc).eof())
	{
		char c = 0;
		wcstombs(&c, &wc, 1);
		std::cout.put(c);
	}
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

 

by: DFlaschenPosted on 2008-05-25 at 18:54:33ID: 21644299

IN all fairness, I haven't yet studied what you wrote.
Is there a dog-simple way to do this.
For example a command-line runnablle program that I could use
    Convert old-file.txt new-file.txt
Thanks

 

by: DFlaschenPosted on 2008-05-25 at 18:57:36ID: 21644314

I just now so your code-snippet.  That's possible too.  But the command-line would be nice.  Forgive my delay in studying what you wrote yet.

 

by: rstaveleyPosted on 2008-05-26 at 01:24:21ID: 21645271

The iconv utility is what Linux/UN*X people use to convert between character formats.

  iconv --from utf-16  --to utf-8 < source-file.txt > destination-file.txt

You can Google for a Win32 port or get up and running with Cygwin.

 

by: rstaveleyPosted on 2008-05-26 at 01:36:58ID: 21645303

If you have a couple of weird looking binary characters at the beginning of your UTF-16 file (0xffef as it is little-endian), and want to use evilrix's utility in http:#21644289, you will need to discard the first wchar_t. This is the BOM (see http://en.wikipedia.org/wiki/Byte_Order_Mark).

 

by: evilrixPosted on 2008-05-26 at 03:56:03ID: 21645667

>> Is there a dog-simple way to do this.
I thought what I posted was simple... 7 lines of code to convert wide to narrow... even hello world is about 3 :)

>> I just now so your code-snippet.  That's possible too.  But the command-line would be nice
That's why I gave you the code... all you have to do is build it and you have a simple command line tool


BTW: It is a quick and dirty bit of code, it has been provided by way of showing you the basics so you can build on it yourself. It won't as rstaveley points out, handle BOM markers correctly. Handling that, though, is simple (as rstaveley explains) and I've left it up to you to do as a learning exercise.

 

by: canaliPosted on 2008-05-26 at 06:56:31ID: 21646454

try this
cmd /A /C type "Norton-Ghost.log.txt" >newNG.txt

 

by: DFlaschenPosted on 2008-05-26 at 16:22:27ID: 21648552

Canali: I tried it.  It didn't work.  Did you try it?  A copy of the actual file is attached to the top of this thread.  You'll find it at the bottom of the initial question, in the Attachments section.  I've attached it here again.  Thanks.

 

by: evilrixPosted on 2008-05-26 at 16:34:04ID: 21648585

Did you try the code I posted above? I see no reason why this wouldn't work.

 

by: DFlaschenPosted on 2008-05-26 at 17:24:16ID: 21648728

I wrote the following program called "utf16_to_utf8.exe":  (See attached code snippet.)
Then I ran the following command from the CMD prompt:
    type "norton Ghost 9.0.log.txt" | utf16_to_utf8.exe >utf8.txt
The program just sat there - it didn't end.  I mean I waited what seemed to be a long time, an dit didn't end.
The part of the program that is unclear is how I am handling the BOM (first) byte.  Maybe I'm not doing that correctly.  (See "if bFirst == FALSE...)
The only other difference is me having added "#include "stdafx.h".
Where did I go wrong?  Thanks

// utf16_to_utf8.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <iostream>
 
int main()
{
	bool bFirst = false;
	wchar_t wc = 0;
	while (!std::wcin.get(wc).eof())
	{
		if (bFirst == false)
		{
			bFirst = true;
			continue;
		}
		char c = 0;
		wcstombs(&c, &wc, 1);
		std::cout.put(c);
	}
	return 0;
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:

Select allOpen in new window

 

by: DFlaschenPosted on 2008-05-26 at 17:33:52ID: 21648770

Well, I'm doing great!
Because I had problems with evilrix's solution, I tried rstaveley's solution.
I downloaded iconv.exe from here: http://sourceforge.net/project/showfiles.php?group_id=25167&package_id=51458
It put an iconv.exe in a Bin folder.  I copied that iconv.exe to the folder with my UTF16 file and entered
       iconv --from utf-16 --to utf-8 < "Norton Ghost 9.0.log.txt" > fixed.txt
It finished VERY fast and created an empty output file
So ... I'm batting 0 for 2 today!

 

by: evilrixPosted on 2008-05-26 at 22:16:37ID: 21649495

>> Because I had problems with evilrix's solution
What problem was that exactly? You can ask for more help you know, I'm happy to give it.

 

by: rstaveleyPosted on 2008-05-27 at 02:12:00ID: 21650396

Oh I forgot about this problem.... You'll find that wcin.get() extracts only one byte from stdin in certain locales (same as wfstream), because the external format is narrow. You'll need to open the file in binary mode to get it to read 16-bits at a time.

 

by: rstaveleyPosted on 2008-05-27 at 02:16:11ID: 21650419

Here's some rumination about this the last time I messed up on this: http:Q_20797258.html#9753379

 

by: rstaveleyPosted on 2008-05-27 at 02:24:46ID: 21650455

> external format

"External representation" is what they call it.

Try writing "Hello, world" into an ofstream in most locales and you'll get a file of 12 bytes (not 24/48 as you might expect in Windows/Linux for wchar_t). That's because your external representation is typically optimised as narrow (char) and internal representation optimised as wide (wchar_t).

 

by: matrixnzPosted on 2008-05-27 at 02:34:18ID: 21650501

I had to read the file as Binary and then convert it to UTF16 Little Endian to read the file

I wrote a script with AutoIT ( I was feeling bored) which will work from Command Prompt i.e
Convert OldText.txt NewText.txt.

I've compiled to an exe and can be found here http://matrixnz.321.co.nz/Convert.exe

Or if you wish to compile yourself

Download and Install AutoIT and also AutoIT Script Editor found here - http://www.autoitscript.com/autoit3/downloads.shtml
AutoIt is a freeware Windows automation language.

Once installed, copy and paste the code snippet into Scite (AutoIT Script Editor), save the file as Convert.au3 and then click Tools -> Build this will create the Convert.exe in the same folder as the Script.

From a command prompt you can use:
Convert /? for help
examples
Convert Norton-Ghost.log.txt NewText.txt
or
Convert "Norton Ghost.log.txt" "New Text.txt"

Cheers

#NoTrayIcon
#AutoIt3Wrapper_Change2CUI=y
 
If	$CmdLine[0] < 3 Then
	If $CmdLine[1] = "/?" Then
		ConsoleWrite("Usage:" & @CRLF)
		ConsoleWrite(@TAB & "Convert [/? | <inputfile.txt> | <outputfile.txt> |" & @CRLF & @CRLF)
		ConsoleWrite(@TAB & "Options:" & @CRLF)
		ConsoleWrite(@TAB & "   /?" & @TAB & @TAB & @TAB & "Display this help message" & @CRLF)
		ConsoleWrite(@TAB & "   <inputfile.txt>" & @TAB & "UDF Text File to Convert" & @CRLF)
		ConsoleWrite(@TAB & "   <outputfile.txt>" & @TAB & "Converted Text File" & @CRLF & @CRLF)
		ConsoleWrite(@TAB & "Example:" & @CRLF)
		ConsoleWrite(@TAB & "   Convert ""UDF File.txt"" ""Output File.txt""" & @CRLF & @CRLF)
		Exit
	Else
		$Input = StringRight($CmdLine[1], 4)
		If $Input = ".txt" Then
			$INP_FILE = FileOpen($CmdLine[1], 16)
			If @error = -1 Then
				ConsoleWrite("Input File is invalid")
			EndIf
			$READ_FILE = FileRead($INP_FILE)
			FileClose($INP_FILE)
		Else
			ConsoleWrite("Error: No Input File specified.  Please see help [ /? ] for options" & @CRLF)
			Exit
		EndIf
	EndIf
 
	If $CmdLine[0] = 2 Then
		$Output = StringRight($CmdLine[2], 4)
		If $Output = ".txt" Then
			$OUT_FILE = FileOpen($CmdLine[2], 34)
			If @error = -1 Then
				ConsoleWrite("Output File is invalid")
			EndIf
			FileWrite($OUT_FILE, $READ_FILE)
			FileClose($OUT_FILE)
			Exit
		Else
			ConsoleWrite("Error: No Output File specified. Please see help [ /? ] for options")
			Exit
		EndIf
	Else
		ConsoleWrite("Error: No Output File specified. Please see help [ /? ] for options")
		Exit
	EndIf
Else
		ConsoleWrite("Error: Please see help [ /? ] for options")
		Exit
EndIf
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:

Select allOpen in new window

 

by: rstaveleyPosted on 2008-05-27 at 02:40:41ID: 21650520

Typo

> Try writing "Hello, world" into an ofstream in most locales

Try writing "Hello, world" into an owfstream in most locales

 

by: rstaveleyPosted on 2008-05-27 at 02:42:21ID: 21650529

> I had to read the file as Binary

Yes, that's the right thing to do.

 

by: rstaveleyPosted on 2008-05-27 at 02:54:25ID: 21650586

At the risk of flogging a dead horse, the following snippet shows you how to have a wide "external representation".

There is no BOM handling, but I notice DFlaschen's .txt file doesn't appear to have a BOM anyhow and I couldn't think of an elegant way to handle the BOM in IOStreams, when I last played with this in 2003/2004.

This writes four characters into a "wide" file and reads them from a "wide" file, doing the right thing with IOStreams, by imbuing a "no conversion" locale to see that the external representation is wide. You can of course hack this to read the .txt file and then write a .txt without imbuing the "no conversion" locale.

Very silly, isn't it?  I hope it's educational though.

#include <iostream>
#include <fstream>
#include <string>
#include <locale>
 
namespace noconv {
 
class codecvt : public std::codecvt<wchar_t,char,mbstate_t> {
public:
	explicit codecvt(size_t refs = 0) : std::codecvt<wchar_t,char,mbstate_t>(refs) {}
protected:
	virtual	result do_in(
		state_type& state
		,const extern_type *from_begin
		,const extern_type *from_end
		,const extern_type *&from_next
		,intern_type *to_begin
		,intern_type *to_end
		,intern_type *&to_next
		) const
	{
	        return noconv;
	}
 
/* Here's where we convert from the internal representation to the external
   representation written to disk */
 
	virtual	result do_out(
		state_type& state
		,const intern_type *from_begin
		,const intern_type *from_end
		,const intern_type *&from_next
		,extern_type *to_begin
		,extern_type *to_end
		,extern_type *&to_next
		) const
	{
		const intern_type *src = from_begin;
		const intern_type *src_end = from_end;
		intern_type *dst = reinterpret_cast<intern_type*>(to_begin);
		intern_type *dst_end = reinterpret_cast<intern_type*>(to_end);
 
		while (dst+1 <= dst_end && src < src_end)
			*dst++ = *src++;
 
		from_next = src;
		to_next = reinterpret_cast<extern_type*>(dst);
 
	        return ok;
	}
	virtual	result do_unshift(
		state_type& state
		,extern_type *to_begin
		,extern_type *to_end
		,extern_type *&to_next
		) const
	{
	        return noconv;
	}
 
	virtual	int do_length(
		state_type& state
		, const extern_type *from_begin
		,const extern_type *from_end
		,size_t max_internal_chars
		) const throw()
	{
	        return std::min(max_internal_chars,size_t(from_end-from_begin));
	}
 
/* Never converts? Not true for us. */
 
	virtual	bool do_always_noconv() const throw()
	{
	        return false;
	}
 
/* Max extern_type for one intern_type */
 
	virtual	int do_max_length() const throw()
	{
	        return sizeof(intern_type);
	}
 
/* do_encoding returns one of the following:
	-1, if the external representation of a character uses
	a stateful encoding
 
	a constant number representing the maximum width in externT
	elements used to represent a character in a fixed-width encoding
 
	0, if the external representation of the characters in the
	character set uses a variable size encoding
 */
 
	virtual	int do_encoding() const throw()
	{
	        return sizeof(intern_type);
	}
};
} // noconv namespace
 
int main()
{
	try {
		std::locale loc(std::locale::classic(),new noconv::codecvt);
		std::wofstream file;
		file.imbue(loc);
		file.open("four_wchars.txt");
		if (!file) {
			std::cerr << "Error: Unable to create file\n";
			return 1;
		}
 
		//std::wstring wstr(L"abc");
		//file << wstr /*<< std::endl*/;
 
		file <<	L"1234";
 
		file.close();
	}
	catch (std::exception e) {
		std::cerr << "Exception: " << e.what() << std::endl;
	}
 
	try {
		std::locale loc(std::locale::classic(),new noconv::codecvt);
		std::wifstream file;
		file.imbue(loc);
		file.open("four_wchars.txt");
		if (!file) {
			std::cerr << "Error: Unable to open file\n";
			return 2;
		}
 
		std::wstring wstr;
 
		file >> wstr;
 
		file.close();
 
		std::wcout << "String is \"" << wstr << "\"\n";
	}
	catch (std::exception e) {
		std::cerr << "Exception: " << e.what() << std::endl;
	}
 
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:

Select allOpen in new window

 

by: rstaveleyPosted on 2008-05-27 at 03:02:04ID: 21650613

ROFL, or should I say WOFL:

>Typo
>
>> Try writing "Hello, world" into an ofstream in most locales
>
>Try writing "Hello, world" into an owfstream in most locales

Try writing "Hello, world" into an wofstream in most locales.

That's it from me now. Sorry for all the inevitable spam from my postings.

 

by: canaliPosted on 2008-05-27 at 04:48:52ID: 21651000

try this
UC2ascii.vbs

Function UnicodeToAscii(ByRef pstrUnicode)
     Dim llngLength
     Dim llngIndex
     Dim llngAscii
     Dim lstrAscii
         
     llngLength = Len(pstrUnicode)
         
     For llngIndex = 1 To llngLength
          llngAscii = Asc(Mid(pstrUnicode, llngIndex, 1))
'          lstrAscii = lstrAscii & ChrB(llngAscii)
          lstrAscii = lstrAscii & (Mid(pstrUnicode, llngIndex, 1))
 
     Next
 
         
     UnicodeToAscii = lstrAscii
End Function
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objFSO, objTgtFile, objSrcFile, strAscii, strTgtFile, strSrcFile, strMsg
 
 
' Check command line arguments
If WScript.Arguments.UnNamed.Count <> 2 Then Syntax( )
If WScript.Arguments.Named.Count    > 0 Then Syntax( )
 
strSrcFile = WScript.Arguments.UnNamed(0)
strTgtFile = WScript.Arguments.UnNamed(1)
strAscii   = ""
strMsg     = ""
 
' Create File System Object and check if source and target files exist
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
If Err Then ShowError( )
If objFSO.FileExists( strSrcFile ) = False Then
	strMsg = vbCrLf & "File not found: " & strSrcFile & vbCrLf
	Syntax( )
End If
If objFSO.FileExists( strTgtFile ) = True Then
	strMsg = vbCrLf & "File exists: " & strTgtFile & vbCrLf
	Syntax( )
End If
 
' Read unicode file and store content in variableù
 
Set objSrcFile = objFSO.OpenTextFile( strSrcFile, ForReading,0,-1 )
If Err Then ShowError( )
While Not objSrcFile.AtEndOfStream
	strUNICODE = strUNICODE & objSrcFile.ReadLine & vbCrLf
WEnd
objSrcFile.Close
 
' Create new  text file
Set objTgtFile = objFSO.CreateTextFile( strTgtFile, True )
If Err Then ShowError( )
objTgtFile.Write UnicodeToAscii(strUNICODE)
objTgtFile.Close
 
 
Sub ShowError()
	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
	         Err.Description & vbCrLf & vbCrLf
	Syntax
End Sub
 
 
Sub Syntax( )
	strMsg = strMsg & vbCrLf _
	       & "UC2ascii.vbs,  Version 1.00" & vbCrLf _
	       & "Convert text from ASCII to Unicode" & vbCrLf & vbCrLf _
	       & "Usage:  CSCRIPT  ASCII2UC.VBS   unicode_file ascii_file " _
	       & vbCrLf & vbCrLf 
	WScript.Echo strMsg
	WScript.Quit(1)
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:

Select allOpen in new window

 

by: DFlaschenPosted on 2008-05-27 at 06:44:25ID: 21651776

MatrixNZ:
Thank you for your program.  I ran it and it worked!
Just one odd thing:  During the run (twice) a message box containing only ".txt" appeared - with an OK button.  I had to press OK twice.  Then the program ended with correct output.  The actual comand line I issued was:
    convert "Norton Ghost 9.0.log.txt" newNG.txt
Thanks again.  

 

by: matrixnzPosted on 2008-05-27 at 07:10:42ID: 21652012

Sorry I must of compiled before removing those message boxes, for debugging purposes.  I've re-compiled and uploaded.  http://matrixnz.321.co.nz/Convert.exe

Cheers

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...