Reputation: 11
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.
Upvotes: 0
Views: 12686
Reputation: 574
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
Upvotes: 0
Reputation: 23797
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" )
Upvotes: 4