LB Booster
« Need help with ... Save as ANSI »

Welcome Guest. Please Login or Register.
Dec 13th, 2017, 9:52pm


Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
LB Umbrella forum
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Need help with ... Save as ANSI  (Read 465 times)
SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 89
xx Need help with ... Save as ANSI
« Thread started on: Jan 16th, 2017, 10:49am »

I have a one line text file. (English text)

The problem is it generated as Unicode I want it ANSI to be useful on WinPC the generator is a program from Apple (Mac).

Can LBB help?

If I use Note Pad by save as then chose ANSI from the combo at the bottom it became fine for WinPC, it accept it.

How can I do that with code? I hope LBB can do that, help Please.

Regards,
Sarmed
« Last Edit: Jan 16th, 2017, 11:17am by SarmedNafi » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 201
xx Re: Need help with ... Save as ANSI
« Reply #1 on: Jan 16th, 2017, 11:11am »

Hello Sarmed

This link
http://stackoverflow.com/questions/700187/unicode-utf-ascii-ansi-format-differences
says that there are no single "unicode", but 4 different ones.
Also, there is no "ANSI".

So you better make it clear first.

As for simple approach -
Does your text supposed to contain letters with codes >128?
Here's my test file - second line is non-Latin (Cyrillic actually)
Code:
Hello there
 

saved in Notepad as "Unicode".

Running this snippet
Code:
open "testUnicode.txt" for input as #1
a$=input$(#1, lof(#1))
close #1
for i =1 to len(a$)
    c$=mid$(a$,i,1)
    print i, asc(c$),
        if asc(c$)>31 then print c$ else print
next
 

gives me, text starts with two marker bytes
then normal Latin goes as pair(single Latin letter - 0 code)
so "Hello there" clearly readable
Codes 13 and 10 correrspond to CR LF pair - new line separator (might be different on MAC)
later is non-Latin code, unreadable.
Code:
1             255           
2             254           
3             72            H
4             0
5             101           e
6             0
7             108           l
8             0
9             108           l
10            0
11            111           o
12            0
13            32
14            0
15            116           t
16            0
17            104           h
18            0
19            101           e
20            0
21            114           r
22            0
23            101           e
24            0
25            13
26            0
27            10
28            0
29            31
30            4
31            64            @
32            4
33            56            8
34            4
35            50            2
36            4
37            53            5
38            4
39            66            B
40            4
 


If it will be in your case, you can just keep every other letter and have ordinary ASCII text.

Code:
a$=mid$(a$,3)   'strip 2 marker bytes
for i =1 to len(a$) step 2  'every second one
    c$=mid$(a$,i,1)
    print i, asc(c$),
        if asc(c$)>31 then print c$ else print
next
 
« Last Edit: Jan 16th, 2017, 11:16am by tsh73 » User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 89
xx Re: Need help with ... Save as ANSI
« Reply #2 on: Jan 16th, 2017, 11:21am »

Hi Anatoly,

Thank you for responding. The text is English, Absolutely English the PC don't respond to it, because of the reason which I mentioned to it.

And it is readable in both cases, No problem with that.
Regards,
« Last Edit: Jan 16th, 2017, 11:23am by SarmedNafi » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 201
xx Re: Need help with ... Save as ANSI
« Reply #3 on: Jan 16th, 2017, 11:29am »

Also, last function (Reply#9) from this LB thread
http://libertybasic.conforums.com/index.cgi?board=LB3&action=display&num=1246653111
works for me.
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 89
xx Re: Need help with ... Save as ANSI
« Reply #4 on: Jan 16th, 2017, 11:52am »

Thank you Anatoly,

The conversion succeeded.

The one line text file became ANSI and accepted by WinPC.

All the best,
Sarmed
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1291
xx Re: Need help with ... Save as ANSI
« Reply #5 on: Jan 16th, 2017, 5:47pm »

on Jan 16th, 2017, 11:11am, tsh73 wrote:
This link ... says that there are no single "unicode", but 4 different ones.

There's only one 'Unicode' (the whole point is that it's 'universal') but there are different encodings. However, as far as LBB is concerned (and the web, and email, and most other places), there is only one encoding that really matters: UTF-8.

If you are unsure about the 'universality' of UTF-8 then you might find this document enlightening.

To answer the OP's question yes, you can use LBB's program editor to convert between ANSI and UTF-8 or vice-versa (assuming there are no non-ANSI characters in the text of course). In the Options menu select the mode corresponding to the source file (Unicode or non-Unicode) then load or paste the source text into the editor. Change the setting in the Options menu and save the text to a new file. Job done!

Richard.

P.S. The thread at the LB Community Forum to which you linked reveals a chasm of misunderstanding about what Unicode and ANSI are. It's disappointing that something so important is so poorly understood.
« Last Edit: Jan 16th, 2017, 5:52pm by Richard Russell » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 201
xx Re: Need help with ... Save as ANSI
« Reply #6 on: Jan 16th, 2017, 6:55pm »

Thanks for entertaining reading.
(from the text) It really looks like coding in Windows and avoiding UTF-16 is akin to pissing against the wind.
Also
Quote:
FAQ
1. Q: Are you a linuxer? Is this a concealed religious fight against Windows?

Number one question. They did suspect something wink
'Nuff said.
« Last Edit: Jan 16th, 2017, 6:58pm by tsh73 » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1291
xx Re: Need help with ... Save as ANSI
« Reply #7 on: Jan 16th, 2017, 8:17pm »

on Jan 16th, 2017, 6:55pm, tsh73 wrote:
It really looks like coding in Windows and avoiding UTF-16 is akin to pissing against the wind.

But how often do you (or anybody) actually use UTF-16 when coding for Windows? I'm willing to bet that actually you use UCS-2, i.e. you assume that every character can be represented as 16-bits (two bytes).

That is the problem with UTF-16; it's neither one thing nor the other. It doesn't have the advantage of UTF-32 (every character can be represented by the same-size code) or of UTF-8 (an efficient byte-stream identical to ANSI when only ASCII characters are used). UTF-16 has the disadvantages of both!

Anyway, UTF-8 has long since won the race. It's the only Unicode encoding used on the web. It's the only Unicode encoding used in emails. It's the encoding used in SDL2 and it's the Unicode encoding used by LBB.

Richard.
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 89
xx Re: Need help with ... Save as ANSI
« Reply #8 on: Jan 17th, 2017, 09:38am »

Thank you Richard for interact,

Quote:
To answer the OP's question yes, you can use LBB's program editor to convert between ANSI and UTF-8 or vice-versa


Unfortunately this way did not help (I know this way), it must be done by coding, the code open the file read it convert it then saving as a new file. At last attach the new file to a program built in WinPC to Run.

All this done by one LBB exe. I finished do the job with the help of first post of Anatoly, by adding
Code:
...   ...   ...
...   ...   ...

d$ = d$ + c$
next

    open "Speak2.txt" for output as #2
        #2 d$
        close #2
        'speak the number
        c$ = "Speak2.txt" 
                'print c$
        b$ = "cscript.exe speak.vbs "; c$
        run b$, hide
End

 


The response of Anatoly was just in time, I thank him very much.
And I thank Richard very much for one file LBB exe.

Unfortunately about half an hoer from now, I will be off line for a month or so.

Regards,
Sarmed
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 89
xx Re: Need help with ... Save as ANSI
« Reply #9 on: Jan 17th, 2017, 09:45am »

> Change the setting in the Options menu and save the text to a new file.

I was asked you to put a code which we can use it to control the check box via code. You refused, or you don't replay for that request.

Regards,
Sarmed
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1291
xx Re: Need help with ... Save as ANSI
« Reply #10 on: Jan 17th, 2017, 11:43am »

on Jan 17th, 2017, 09:45am, SarmedNafi wrote:
I asked you to put a code which we can use it to control the check box via code. You refused, or you don't replay for that request.

I refer you to the Directives section of the Help file:
  • %options ansi
    This directive selects ANSI character encoding, overriding (and changing if necessary) the current selection in the Options menu; it should normally be inserted at or near the start of the program. Note that there must not be a space after the percent sign.

  • %options unicode
    This directive selects Unicode (UTF-8) character encoding, overriding (and changing if necessary) the current selection in the Options menu; it should normally be inserted at or near the start of the program.
I do not think it is very fair to claim that I "refused" your request, when on the contrary the very feature you asked for was added in a subsequent release of LBB.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls