Hi,
I have/had problems with Norwegian characters like æ å and the ø (theese are the html-entities).
I know there is a function in ASP, the Server.HTMLEncode(), which can convert theese and more.
The problem is that I also have HTML inside the string, as this is my custom CMS.
This means I cant use the Server.HTMLEncode(), as then it would render the HTML like <img.. /> as pure text!
So, I made my own function, with a dictionary.
Its quite simple and it worked like a charm!
The output of my dummy-function was:
And this is correct! It replaces the keys with the items..
Here is my code:
Yes, I told you the function works.. And so it does..
However, my problem here.. and what scratches my head, is that when I post to the ASP file and send the posted value to the function, it for some reason does not work :S
This is how I do it, when it doesent work:
Or, it does work.. I know it replaces, as I tried adding more keys and items to the dictionary and it actually replaces the items, but for some reason it seems ASP then decodes it :S
I slightly modified the function to work with my posted asp page:
Then I do it like this:
I hope someone can shed some light on this "issue".
AFAIK, the function works, and it replaces the occurrances of the keys, with the items..
Eg. to test it, I fed it with my name: "Olav Alexander Mjelde" and I added another dictionary item, which then replaced my last name with "test". This worked perfectly.. But it SEEMS it does not replace the occurrances of the Norwegian characters (but I belive it does!). I believe ASP for some reason decodes the characters back to theire non-entity form(?). I hope this comes out clear..
Olav Alexander Mjelde
Admin & Webmaster
I have/had problems with Norwegian characters like æ å and the ø (theese are the html-entities).
I know there is a function in ASP, the Server.HTMLEncode(), which can convert theese and more.
The problem is that I also have HTML inside the string, as this is my custom CMS.
This means I cant use the Server.HTMLEncode(), as then it would render the HTML like <img.. /> as pure text!
So, I made my own function, with a dictionary.
Its quite simple and it worked like a charm!
The output of my dummy-function was:
Ibsens ripsbærbusker og andre buskevekster<hr />
Ibsens ripsbærbusker og andre buskevekster
And this is correct! It replaces the keys with the items..
Here is my code:
Code:
Function replaceChars(strInput)
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "Æ", "Æ"
d.Add "æ", "æ"
d.Add "ø", "ø"
d.Add "Ø", "Ø"
d.Add "Å", "Å"
d.Add "å", "å"
'd.Key("i") = "it"
'Response.Write("The key i has been set to it, and the value is: " & d.Item("n") & " " & d.Count)
Dim counter, keys, items
keys = d.Keys
items = d.Items
counter=0
for counter = 0 to UBound(keys)
strInput = Replace(strInput, keys(counter), items(counter))
next
response.write (strInput & "<hr />" & text)
End Function
Yes, I told you the function works.. And so it does..
However, my problem here.. and what scratches my head, is that when I post to the ASP file and send the posted value to the function, it for some reason does not work :S
This is how I do it, when it doesent work:
Or, it does work.. I know it replaces, as I tried adding more keys and items to the dictionary and it actually replaces the items, but for some reason it seems ASP then decodes it :S
I slightly modified the function to work with my posted asp page:
Code:
Function replaceChars(strInput)
Dim strOutput
strOutput = strInput
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "Æ", "Æ"
d.Add "æ", "æ"
d.Add "ø", "ø"
d.Add "Ø", "Ø"
d.Add "Å", "Å"
d.Add "å", "å"
Dim counter, keys, items
keys = d.Keys
items = d.Items
counter=0
for counter = 0 to UBound(keys)
strOutput = Replace(strOutput, keys(counter), items(counter))
next
'Response.Write (strOutput & " - " & strInput & "<hr />")
fixText = strInput
End Function
Then I do it like this:
Code:
'Add a new record to the recordset
replaceChars(Request.Form("txtSubject"))
rsAddComments.Fields("innhold_tittel") = fixText
replaceChars(Request.Form("txtIngress"))
rsAddComments.Fields("innhold_ingress") = fixText
replaceChars(Request.Form("txtTekst"))
rsAddComments.Fields("innhold_tekst") = fixText
I hope someone can shed some light on this "issue".
AFAIK, the function works, and it replaces the occurrances of the keys, with the items..
Eg. to test it, I fed it with my name: "Olav Alexander Mjelde" and I added another dictionary item, which then replaced my last name with "test". This worked perfectly.. But it SEEMS it does not replace the occurrances of the Norwegian characters (but I belive it does!). I believe ASP for some reason decodes the characters back to theire non-entity form(?). I hope this comes out clear..
Olav Alexander Mjelde
Admin & Webmaster