ho trovato la risposta here:
Const adTypeBinary = 1
Const adTypeText = 2
' accept a string and convert it to Bytes array in the selected Charset
Function StringToBytes(Str,Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type = adTypeText
Stream.Charset = Charset
Stream.Open
Stream.WriteText Str
Stream.Flush
Stream.Position = 0
' rewind stream and read Bytes
Stream.Type = adTypeBinary
StringToBytes= Stream.Read
Stream.Close
Set Stream = Nothing
End Function
' accept Bytes array and convert it to a string using the selected charset
Function BytesToString(Bytes, Charset)
Dim Stream : Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Charset = Charset
Stream.Type = adTypeBinary
Stream.Open
Stream.Write Bytes
Stream.Flush
Stream.Position = 0
' rewind stream and read text
Stream.Type = adTypeText
BytesToString= Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
' This will alter charset of a string from 1-byte charset(as windows-1252)
' to another 1-byte charset(as windows-1251)
Function AlterCharset(Str, FromCharset, ToCharset)
Dim Bytes
Bytes = StringToBytes(Str, FromCharset)
AlterCharset = BytesToString(Bytes, ToCharset)
End Function
Così ho appena fatto questo:
AlterCharset(str, "ISO-8859-1", "UTF-8")
e ha funzionato bene.
Per quanto riguarda la ricerca sul sito, questa è stata esaudita, dalla tua vera e da altre mille volte già! Ad esempio, sfoglia la sezione ** Related ** sul lato destro di questa domanda. – Lankymart
possibile duplicato di [convertire utf-8 in iso-8859-1 in classico asp] (http://stackoverflow.com/questions/17677180/convert-utf-8-to-iso-8859-1-in-classic- asp) – Lankymart
@Lankymart Ho visto questa domanda, ma la sua risposta riguarda l'intero file di script. Voglio convertire una stringa originata in un database, quindi non è nemmeno specificata in quel file. Devo convertire solo una singola stringa e mantenere il resto del file così com'è (ISO-8859-1). Ma io sono nuovo di ASP classico, e potrebbe non essere afferrando la risposta correttamente. Visto questo chiarimento, credi che sia così? Se sbaglio, chiederò chiarimenti sui commenti di quella risposta. – Metalcoder