java - Translating strings character by character -


Text after "div class =" itemprop = "text">

How do I get a string made of Latin characters that translate into a string made of a different Let's think about implementing the set of characters, regard Cyrillic

Here's how it is done in PHP for example:.

  function latin_to_cyrillic ($ string) {$ array = array ("а" = "a", "b" => gt; "b", "u" => "", "G" = "gt" = "gt" = "gt" = "gt" = "gt" = "I", "ee" = "i", "й" => "y", "k" = "gt" "E", "ji" = & gt; "zh", "o", "o" => gt; "o", "p" = & gt; "k", "л" => L "," m "=" gtc: "m", "н" =>, "p", "р" => "r", "c" = & gt; "s" "T" = & gt; "t", "у" = & gt; "u", "ф" = "f", "f" = & gt; "f", "f" = & gt; "f "Y", "ü" = & gt; "one", "ю" = & gt; "you", "я", "y" = & Gt; "G", "B", "Vi" = & gt; "V", "G" = " D = "" E = "" E "," E "," Ж "=" gt "," z "= & gt;" jade "," e "=> I, "" Й "= & gt;" Y "," C "=>," K "," L "=>," L "," M "= & gt;" A "P", "r" = & gt; "r", "c" = "gtc: = "Gtc: mediawiki-xid =" gtc: mediawiki-xid = "gtc: mediawiki-xid =" gtc: , "C" = & gt; "ts", "Ч" => f, "Ш" => "sh", "Щ" = & gt; "Shunt", "Ь" = & gt; "Y", "Ъ" = & gt; "A", "U" => "U", "U" => "Yes", "-" => "-"); Return str_replace (array_values ​​($ array), array_keys ($ array), $ string); }   

Firstly, you need a conversion table, translation for each character Define

Then you read the string with four characters, and use the translation table to get the translation. Easy, right?

You can use something like this:

  class translator {hashmop & lt; String, string & gt; Translation = New Hashmap & lt; String, string & gt; (); Public translator () {// host a translation here; } Public String Translation (String origin) {String Destination = ""; For (int i = 0; i & lt; orig.length (); i ++) {char character = original.charAt (i); Destiny = destiny + translation.get (character.Tosting (character)); } Return fortune; }}  

Alternatively you can use

  replaceEach (string text, string [] searchList, string [] replacementList) all events of strings Changes between another string of  

to org.apache.commons.lang.StringUtils . You can populate a string [] with Latin letters (but in the form of string ), then another string [] In the filled with Cyrillic characters, use the string , and that function. String [] latinCharacters = [] // Populate them String [] cyrillicCharacters = [] // populate them to translate the public string (string origin) {replace replace every (original, Latin camera) , Ceramic caterers); }


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -