0

Good day

I need help on converting a ANSI TXT file into UTF8 txt file. using Foxpro as programming language. or Xbase

the thing is that i am creating and writing on the txt file using Foxpro, but i need to save the file as a UTF8 because it´s supossed to be read by another system.

Edson Magaia
  • 11
  • 1
  • 1
  • 2
  • I'm voting to close this question as off-topic because SO is here to help with code you wrote but SO is not here to write code for you or to supply a tutorial. – Rob Jul 25 '17 at 13:28
  • Sorry about that Rob, – Edson Magaia Jul 25 '17 at 14:49
  • Do a Google search for: vfp txt to utf8 and you will find how others have done this. One challenge you face is trying to use an OLD version of Foxpro with a more limited command set - Visual Foxpro 9 makes things simpler. – Dhugalmac Jul 25 '17 at 14:57

2 Answers2

4

mycursor is an alias and StrToFile() with that alias would be meaningless. Probably what you are trying to achieve is this:

StrToFile( Strconv(FileToStr( "c:\test.txt" ),9), "c:\test_utf8.txt" )
Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39
0

By looking over the Google Search results that I suggested above I find the following:

func utf8encode( lcString )
local lcUtf, i

lcUtf = ""
for i = 1 to len(lcString)
    c = asc(substr(lcString,i,1))
    if  c < 128
        cUtf = cUtf+chr(c)
    else
        cUtf = cUtf+chr(bitor(192,bitrshift(c,6)))+chr(bitor(128,bitand(c,63)))
    endif
next

return cUtf  

Note: That is not my own code and I have not tested it, but the poster on the other site indicated that it worked in the OLD version of Foxpro they were using.
Also it wouldn't surprise me much if the code needed modification to work for you.

EDIT: Obviously that code is just a FUNCTION() which would receive the intended String and then convert it to UTF8.
Once done, it would return the string to the calling routine which would then need to convert the String into a File using VFP's STRTOFILE() function.

Alternatively, if you were using VFP9 you could use STRCONV() for the String conversion. STRCONV( ) Function

Good Luck

Dhugalmac
  • 554
  • 10
  • 20