Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29594

How do I change the string encoding?

$
0
0

The task is to Write an application to run under the Android OS thattranslates text in the same encoding (for example, win-1251) and writescontent in a different encoding (for example, utf-8) and the reverse task.

When entering a message, I don't touch the encoding at all.

Then I just process a simple tap and a long tap to change the encoding.In other words, if you enter just text, everything works correctly.When you normally click, the ConvertItem method is called.

If you click for a long time, the ConvertItem2 method is called

I do this

const convertItem = (text,key) =>{var iconv = require('iconv-lite');const buf = Buffer.from(text, "binary");const str = iconv.decode(buf, "win1251");setValue(old=>old.map((value)=>{  if(value.key==key){    value.text = str  }  return value}))}const convertItem2 = (text,key) =>{var iconv = require('iconv-lite');const buf = Buffer.from(text, "binary");const str = iconv.decode(buf, "utf8");setValue(old=>old.map((value)=>{  if(value.key==key){    value.text = str  }  return value}))}

Viewing all articles
Browse latest Browse all 29594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>