ShadowStorm
ShadowStorm

Reputation: 851

Converting foreign characters to normal

I have an international photo website. When the office uploads photos that have come from abroad, the captions and headlines sometimes have foreign characters, such as:

1. François Hollande
2. ValŽrie Trierweiler

And these get stored in the database (MySQL – latin1_swedish_ci), as-is. Now, when it comes to searching for Francois, without the French characters, in plain English, those particular photos do not display.

Now this isn't just a problem with French characters – it's other countries too. How is this possible, before I submit to my database, to convert these foreign characters to normal ones, like:

  1. Francois Hollande

Upvotes: 2

Views: 2182

Answers (3)

George SEDRA
George SEDRA

Reputation: 786

And like this it can be a function

Function unaccent(strg)
    With Server.CreateObject("Adodb.Stream")
    .Charset = "ascii"
    .Open
    .WriteText strg
    .Position = 0
    unaccent = .ReadText
    End With
End Function

Upvotes: 1

Kul-Tigin
Kul-Tigin

Reputation: 16950

You can do it using Adodb.Stream with ascii charset. Here is an example:

With Server.CreateObject("Adodb.Stream")
    .Charset = "ascii"
    .Open
    .WriteText "François Hollande ValŽrie Trierweiler ÖÇŞİĞÜöçşığü ôûõòùìñ"
    .Position = 0
    Response.Write .ReadText
End With

Above script must print Francois Hollande ValZrie Trierweiler OCSIGUocsigu ouoouin exactly.

Upvotes: 5

Mihalis Bagos
Mihalis Bagos

Reputation: 2510

This answer will most probably cover your case.

You don't need an external library, and you can check for conformance using a numerous of methods, using regexes being my personal preference for not too large strings.

Upvotes: 0

Related Questions