reactjs - React Javascript displaying/decoding unicode characters -


i have string in unicode need convert. need render string \u00f3 ó. example, should happen other types of characters, á, í, ú...

i have following basic code: https://jsfiddle.net/dddf7o70/

i need convert

<hello name="informaci\u00f3n" /> 

into

información 

if have work strings have, whatever reason, \u.... codes in them instead of being real letters, convert them numbers, , use string.fromcharcode() turn numbers real letters. can use regexp replace handler function this:

function convertunicode(input) {   return input.replace(/\\u(\w\w\w\w)/g,function(a,b) {     var charcode = parseint(b,16);     return string.fromcharcode(charcode);   }); }  var hello = react.createclass({   getinitialstate: function() {     return {       name: convertunicode(this.props.name)     };   },   render: function() {     return <div>hello {this.state.name}</div>;   } });  react.render(   <hello name="informaci\u00f3n" />,   document.getelementbyid('container') ); 

fiddle: https://jsfiddle.net/dddf7o70/4/


Comments

Popular posts from this blog

stringtemplate - StringTemplate4 if conditional with length -

shader - OpenGL Shadow Map -