This question already has answers here:
Converting UTF8 to ANSI (ISO-8859-1) in Delphi
(2 answers)
Closed 3 years ago.
I have spent most of the day looking for a solution but i can't figure it out, so i thought i'd ask the experts here.
In Outlook there is a mail message with attachments, some of the attachments have a filename with words like 'dossier pièces signée'.
We import the mail in the application but we noticed something strange with the filename of the attachment, the filename we save in the database does not match the actual filename.
After a long search i discovered the 'è' character is actually 2 characters and when i paste this in notepadd++ and show it as ansi i get 'pieÌ€ces' instead of 'pièces', so i think (but am unsure) this filename is a url encoded filename.
Since we don't do unicode or utf-8 in our database i think it would be best to store the filename after converting it to ansi, however i can't find any Delphi function that returns it like to the notepad++ format.
Does anyone have any advice please?
In delphi 2010 and after there's a Utf82Ansi internal function.
See more details in that answer here in stackoverflow: Converting UTF8 to ANSI (ISO-8859-1) in Delphi
Related
We have built an email service that reads emails (from IMAP) and put them into a table in a database. And it works for German / English text, but now I want to get all other emails, like Cyrillic or Chinese too. But the characters that I receive are something like this: поново теŃтирам or even just ?????.
We are using ADO objects to store data in database and column type for those fields are declared as nvarchar, also parameters of a stored procedure that is used to upload that data are nvarchar too.
I presume that is the problem with Delphi 2007, but still I read on some posts here and there that Delphi 2007 supports Unicode (if Unicode I need). So, does anybody knows how to read email with Cyrillic and store it in mssql table?
To get text from IdMessage I am using IdMessage.Body.Text
Thanks,
Dejan
And INDY version is 10.1.5
I have managed to make it working by using UTF8Decode function.
I have tested it with UTF-8 and ANSI charsets and it works in both cases (of course ANSI will produce ? in the places of Unicode characters).
declare BodyText and subject as WideStrings
after that just use:
BodyText := UTF8Decode(IdMessage.Body.GetText)
I tried to use Unicode characters in my FTP server's greeting, but the client seems to read them as two different characters each. Because of this, I need a way to encode them into UTF-8. For now, I have the greeting HTML encoded because I am displaying it on a webpage, but on any other client it will display the encoding. How can I set the greeting to be parsed as UTF-8? And if I can't, then is there a way I can parse the greeting correctly?
EDIT: Answered my own question, see below.
I found the answer to the question. It was actually UTF-8 encoded already, and I had to decode it from UTF-8. Here is what I did:
decodeURIComponent(escape(greeting))
Don't forget to replace the line breaks with <br> if you are displaying it on a webpage like I am!
decodeURIComponent(escape(greeting)).replace(/\n/g,'<br>')
I have the following xml that I would like to read:
chinese xml - https://news.google.com/news/popular?ned=cn&topic=po&output=rss
korean xml - http://www.voanews.com/templates/Articles.rss?sectionPath=/korean/news
Currently, I try to use a luaxml to parse in the xml which contain the chinese character. However, when I print out using the console, the result is that the chinese character cannot be printed correctly and show as a garbage character.
I would like to ask if there is anyway to parse a chinese or korean character into lua table?
I don't think Lua is the issue here. The raw data the remote site sends is encoded using UTF-8, and Lua does no special interpretation of that—which means it should be preserved perfectly if you just (1) read from the remote site, and (2) save the read data to a file. The data in the file will contain CJK characters encoded in UTF-8, just like the remote site sent back.
If you're getting funny results like you mention, the fault probably lies either with the library you're using to read from the remote site, or perhaps simply with the way your console displays the results when you output to it.
I managed to convert the "ä¸ç¾" into chinese character.
I would need to do one additional step which has to convert all the the series of string by using this method from this link, http://forum.luahub.com/index.php?topic=3617.msg8595#msg8595 before saving into xml format.
string.gsub(l,"&#([0-9]+);", function(c) return string.char(tonumber(c)) end)
I would like to ask for LuaXML, I have come across this method xml.registerCode(decoded,encoded)
Under that method, it says that
registers a custom code for the conversion between non-standard characters and XML character entities
What do they mean by non-standard characters and how do I use it?
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Standard URL encode function?
I need to transofrm a Delphi string (like TEdit.Caption) in a "url capable" string.
I need this because I will open google maps programmatically like in TEdit I write "High Street, Sydney"
and then i would like to open the browser at maps.google.com/maps?q=High+Street+Sidney
Is there a ready function to do this, also to parse accents?
You can add IdURI unit from Indy to your uses clause, and use TIdURI.URLEncode() method to encode a URL, and TIdURI.Decode() to decode an encoded URL to a normal string.
In my rails app I work a lot with cyrillic characters. Thats no problem, I store them in the db, I can display it in html.
But I have a problem exporting them in a plain txt file. A string like "элиас" gets "—ç–ª–∏–∞—Å" if I let rails put in in a txt file and download it. Whats wrong here? What has to be done?
Regards,
Elias
Obviously, there's a problem with your encoding. Make sure you text is in Unicode before writing it to the text file. You may use something like this:
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
your_unicode_text = ic.iconv(your_text + ' ')[0..-2]
Also, double check that your database encoding is UTF-8. Cyrillic characters can display fine in DB and in html with non-unicode encoding, e.g. KOI8-RU, but you're guaranteed to have problems with them elsewhere.