I have some JSON data from a web service which gives me data like the following
blah blah <greek>a</greek>
I need to be able to convert what is inside the greek tags into their symbol equivalent, using javascript.
Any ideas?
I have some JSON data from a web service which gives me data like the following
blah blah <greek>a</greek>
I need to be able to convert what is inside the greek tags into their symbol equivalent, using javascript.
Any ideas?
This isn't a full solution, but I think this is the basic idea...
// The difference between standard ascii and greek
var diff = 913-65;
var originalString = "A";
var charCode = x.charCodeAt(0)+diff;
var output = String.fromCharCode(charCode);
Interesting problem, hopefully this will help.
If this is for the occasional Greek letter and not for Greek Text than the W3C is fine with the following code (http://www.w3.org/TR/html4/sgml/entities.html#h-24.3)
function greekSymbol(str) {
if(str.length == 0) {
return "";
}
return String.fromCharCode(str.charCodeAt(0) + (913 - 65)) + greekSymbol(str.substring(1));
}
There's no obvious generic way to do this, as there is no obvious relation. On the other hand, there is a finite set of greek characters. By extension that means there's a finite set of mappings. It should be trivial to find the ASCII character your JSON provider sends for each greek character. pre/postfix the tags forch each. Then, it's a simple search-and replace.