views:

711

answers:

4

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?

A: 

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.

Greek Codes

Ascii Codes

chills42
good idea, except the letters don't correspond 1-to-1, You'd want Nu = N and Omicron = O for example, but Xi is in between.
Jimmy
A: 

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)); 
}
ihumanable
+1  A: 

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.

MSalters
+1  A: 

http://grapse.gr this might be helpful.

Alex