Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print strings with accents and special chars
#1
Hi to all !!!

I have a little program that reads the contents of a folder (with _FILES$ function), then stores them in a string array, and finally it prints all the array on screen.

My problem is that I have accents and special chars on names (I am from Spain, we have Ñs and á é í ó ú).

I tried with  _UPrintString (x, y), NAME(i), , 8,font  ... but it only works with standard file names with no accents Sad
If the name has no special chars it shows the name correctly, but with accents or Ñs it shows an empty string.

What am I doing wrong?

Thank U very much !!! Wink
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#2
First question: Have you loaded a font with the Unicode characters in it with _LoadFont and _Font?
Reply
#3
Yes, I am using Arial Narrow
Font = _LoadFont("C:\WINDOWS\FONTS\ARIALNB.TTF", 20)
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#4
Use _MapUnicode with correct data block for Spain. Press Shift +F1 in IDE then alphabetical/ _mapunicode and search your code page data block and example program.


Reply
#5
I tested this program:

Code: (Select All)
Screen 0
Dim MyFont As Long
MyFont = _LoadFont("C:\WINDOWS\FONTS\ARIALNB.TTF", 40) 'select monospace font

Restore Microsoft_pc_cp850 'or restore single DATA field w/o field name
For ascii = 128 To 255 'assign unicode values to ascii 128 to 255 only
    Read unicode&
    If unicode& = 0 Then unicode& = 9744 'make undefined characters look like a box
    _MapUnicode unicode& To ascii 'replace ascii with unicode value
Next

Screen _NewImage(1024, 768, 32)
_PrintMode _KeepBackground
_Font MyFont

For code = 128 To 255
    Print code; Chr$(code); 'display unicode characters
Next

End

Microsoft_pc_cp850:
Data 199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197
Data 201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,402
Data 225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187
Data 9617,9618,9619,9474,9508,193,194,192,169,9571,9553,9559,9565,162,165,9488
Data 9492,9524,9516,9500,9472,9532,227,195,9562,9556,9577,9574,9568,9552,9580,164
Data 240,208,202,203,200,305,205,206,207,9496,9484,9608,9604,166,204,9600
Data 211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180
Data 173,177,8215,190,182,167,247,184,176,168,183,185,179,178,9632,160

It shows correctly the special chars, but I don't know how to adapt it to my program
I tried to _MAPUNICODE before writing on screen my file names, but it is not working, it is showing blank strings (if the string has special chars) Sad
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#6
I've reduced my program to the bare minimum, in order to try several printing options:

Code: (Select All)
Option _Explicit

Dim As Integer Ascii, Maximo
Dim As String Archivo, Ruta
Dim As Long Unicode, Fuente

Ruta = "C:\My Program Files\Externo virtual\Test"

Screen _NewImage(640, 480, 32)

Fuente = _LoadFont("C:\WINDOWS\FONTS\ARIALNB.TTF", 40)

Restore Microsoft_pc_cp850 'or restore single DATA field w/o field name
For Ascii = 128 To 255 'assign unicode values to ascii 128 to 255 only
    Read Unicode&
    If Unicode& = 0 Then Unicode& = 9744 'make undefined characters look like a box
    _MapUnicode Unicode& To Ascii 'replace ascii with unicode value
Next

Maximo = 1
Archivo = _Files$(Ruta + "\*.*")
_Font Fuente

Cls
Color _RGB(255, 255, 255)

Do While Archivo <> ""
    Dim puntoPos As Long
    puntoPos = InStr(Archivo, ".")
    If puntoPos > 0 Then
        Dim ext As String
        ext = LCase$(Mid$(Archivo, puntoPos + 1))
        If ext = "mp4" Or ext = "avi" Or ext = "mkv" Or ext = "mov" Or ext = "wmv" Or ext = "flv" Then
            Maximo = Maximo + 1
            _UPrintString (0, Maximo * 20), Archivo, , 0, Fuente
            _UPrintString (0, Maximo * 40), Archivo, , 8, Fuente
            _PrintString (0, Maximo * 60), Archivo
            Print Archivo
        End If
    End If
    Archivo = _Files$
    _Display
Loop

End

Microsoft_pc_cp850:
Data 199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197
Data 201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,402
Data 225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187
Data 9617,9618,9619,9474,9508,193,194,192,169,9571,9553,9559,9565,162,165,9488
Data 9492,9524,9516,9500,9472,9532,227,195,9562,9556,9577,9574,9568,9552,9580,164
Data 240,208,202,203,200,305,205,206,207,9496,9484,9608,9604,166,204,9600
Data 211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180
Data 173,177,8215,190,182,167,247,184,176,168,183,185,179,178,9632,160



This is my result:


[Image: Sin-t-tulo.png]


But this is the original file name:


[Image: Sin-t-tulo.png]
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#7
Try using the DATA values for codepage Win-1252 instead of Pc-850.
https://qb64phoenix.com/qb64wiki/index.p...es#CP_1252
Reply
#8
(12-03-2025, 02:09 PM)RhoSigma Wrote: Try using the DATA values for codepage Win-1252 instead of Pc-850.
https://qb64phoenix.com/qb64wiki/index.p...es#CP_1252

IT WORKS !!!!!!!!!!!!!!!!!
THANK YOU VERY MUCH !!!!!!!!!!! Smile Smile Smile Smile Smile
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#9
yeah in the years this question about portability of screen output and keyboard or file input runs over and over.
Maybe it must be showed into FAQ of wiki so the solution is visible for all new users...
I remember that at the time of QB64 SDL I got the help of Clippy and then from another Czech user(sorry my bad memory doesn't let me remember his name)  that showed me how to performing  the task by using _mapunicode.
Some years after I collaborated with Steve to map keyboard input with _deviceinput(1). I got and published in that thread the set for Italian and West Europe code set.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac print #file crlf? BlameTroi 5 318 02-16-2026, 08:42 PM
Last Post: BlameTroi
  Are sub-strings strings? PhilOfPerth 19 1,274 12-27-2025, 01:57 PM
Last Post: Kernelpanic
  Tab() special behaviour in Console? zaadstra 17 1,256 12-06-2025, 02:08 PM
Last Post: bplus
  blue circle isn't drawing and print isn't working? madscijr 12 2,300 09-21-2024, 06:13 PM
Last Post: madscijr
  Assign print using to a string. eoredson 10 1,872 04-02-2024, 02:56 AM
Last Post: SMcNeill

Forum Jump:


Users browsing this thread: 1 Guest(s)