UTF-8 to ANSI

January 3, 2011 at 16:55:12
Specs: Windows 7, Q9550 / 4 Gig
Hi and A Happy New Year!

I am making a winapp with VB express 2008 and I have met a problem with a batch file that will be called in some point by the winapp. Batch contains a command which executes another program (written in jruby). The command will be set by the application and user's input.

The problem is that the winapp is copying the strings encoded in UTF-8 thus the batch file is encoded the same and cannot be executed. After some tries I noticed that it works only if it is encoded as ANSI. I also tried to make first a txt from application and using another batch to make the final batch or another txt encoded in ansi but with no lack. Is there a way to encode a UTF-8 batch (or txt) to ANSI?

Thanks in advance!


See More: UTF-8 to ANSI

Report •


#1
January 3, 2011 at 18:04:35
How are you making the file? Wouldn't it just be easier to create it in ASCII?

How To Ask Questions The Smart Way


Report •

#2
January 3, 2011 at 20:14:50
:: 
:: stripU.bat  Tue 04-01-2011  9:39:55.40
@echo off > newfile & setLocal enableDELAYedeXpansion

call :makeASC

for /f "tokens=* delims= " %%a in (UTF) do (
echo.%%a | ASCII
echo.
) >> newfile

goto :eof

:makeASC

@echo off > #.d
>  #.d echo E0100 FC BA 4C 01 B9 00 FC 33 DB B4 3F CD 21 8B C8 8B
>> #.d echo E0110 F2 8B FA AC 3C 20 74 1C 3C 2E 74 18 3C 2F 76 15
>> #.d echo E0120 3C 39 76 10 3C 41 72 0D 3C 5A 76 08 3C 61 72 05
>> #.d echo E0130 3C 7A 77 01 AA E2 DC 50 8B CF 2B CA BB 01 00 B4
>> #.d echo E0140 40 CD 21 58 CD 20
>> #.d echo Nascii.com
>> #.d echo RCX
>> #.d echo 0046
>> #.d echo W
>> #.d echo Q

debug < #.d > nul
del #.d
del ascii.com

goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
January 4, 2011 at 01:40:38
Thanks a lot for all responses.

# Razor2.3

The problem is that when I add the string that is extracted by VB, it is converted in UTF-8.

# Mechanix2Go

It didn't work. It makes a new file but empty. It returns 2 errors:

a) 'debug' is not an internal... (etc.)

b) cannot find ascii.com fie in ...(etc.)


Report •

Related Solutions

#4
January 4, 2011 at 03:12:41
You can get ascii.com here:

http://golden-triangle.com/ASCII.ZIP

=====================================

@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (UTF) do (
echo.%%a | ASCII
echo.
) >> newfile


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
January 4, 2011 at 04:08:37
No luck because ascii.com is not compatible with 64 bit OS.

Thanks


Report •

#6
January 4, 2011 at 06:46:12
Husserl: The problem is that when I add the string that is extracted by VB, it is converted in UTF-8.
If you don't specify an encoding, .NET will use UTF-8. If you do specify an encoding, you can tell VB to write files in ASCII.

How To Ask Questions The Smart Way


Report •

#7
January 4, 2011 at 07:40:38
#Razor2.3: If you don't specify an encoding, .NET will use UTF-8. If you do specify an encoding, you can tell VB to write files in ASCII.

I do not specify any encoding:

My.Computer.FileSystem.WriteAllText(SomeFile, _
SomeString, True)

But I suppose I better check VB coding forum as well.


Report •

#8
January 4, 2011 at 07:45:02
Use:
My.Computer.FileSystem.WriteAllText(SomeFile, _
SomeString, True, System.Text.Encoding.ASCII)

How To Ask Questions The Smart Way


Report •

#9
January 4, 2011 at 08:36:55
Excellent! Thanks a lot Razor2.3 and of course Mechanix2Go, you guys are a valuable help!

Report •

Ask Question