Issue With Unicode Dictionary

SiamIT

Well-known member
Joined
Aug 3, 2021
Messages
53
Programming Experience
5-10
Greetings,

i have tried to convert a js code to c#..

here is the js code:
C#:
var uni2bijoy_string_conversion_map={"।":"|","‘":"Ô","’":"Õ","“":"Ò","”":"Ó","্র্য":"ª¨","র‌্য":"i¨","ক্ক":"°","ক্ট":"±","ক্ত":"³","ক্ব":"K¡","স্ক্র":"¯Œ","ক্র":"µ","ক্ল":"K¬","ক্ষ":"¶","ক্স":"·","গু":"¸","গ্ধ":"»","গ্ন":"Mœ","গ্ম":"M¥","গ্ল":"M","গ্রু":"Mªy","ঙ্ক":"¼","ঙ্ক্ষ":"•¶","ঙ্খ":"•L","ঙ্গ":"½","ঙ্ঘ":"•N","চ্চ":"”P","চ্ছ":"”Q","চ্ছ্ব":"”Q¡","চ্ঞ":"”T","জ্জ্ব":"¾¡","জ্জ":"¾","জ্ঝ":"À","জ্ঞ":"Á","জ্ব":"R¡","ঞ্চ":"Â","ঞ্ছ":"Ã","ঞ্জ":"Ä","ঞ্ঝ":"Å","ট্ট":"Æ","ট্ব":"U¡","ট্ম":"U¥","ড্ড":"Ç","ণ্ট":"È","ণ্ঠ":"É","ন্স":"Ý","ণ্ড":"Ê","ন্তু":"š‘","ণ্ব":"Y^","ত্ত":"Ë","ত্ত্ব":"Ë¡","ত্থ":"Ì","ত্ন":"Zœ","ত্ম":"Z¥","ন্ত্ব":"š—¡","ত্ব":"Z¡","থ্ব":"_¡","দ্গ":"˜M","দ্ঘ":"˜N","দ্দ":"Ï","দ্ধ":"×","দ্ব":"˜¡","দ্ব":"Ø","দ্ভ":"™¢","দ্ম":"Ù","দ্রু":"`ª“","ধ্ব":"aŸ","ধ্ম":"a¥","ন্ট":"›U","ন্ঠ":"Ú","ন্ড":"Û","ন্ত্র":"š¿","ন্ত":"š—","স্ত্র":"¯¿","ত্র":"Î","ন্থ":"š’","ন্দ":"›`","ন্দ্ব":"›Ø","ন্ধ":"Ü","ন্ন":"bœ","ন্ব":"š^","ন্ম":"b¥","প্ট":"Þ","প্ত":"ß","প্ন":"cœ","প্প":"à","প্ল":"c","প্স":"á","ফ্ল":"d¬","ব্জ":"â","ব্দ":"ã","ব্ধ":"ä","ব্ব":"eŸ","ব্ল":"e","ভ্র":"å","ম্ন":"gœ","ম্প":"¤ú","ম্ফ":"ç","ম্ব":"¤^","ম্ভ":"¤¢","ম্ভ্র":"¤£","ম্ম":"¤§","ম্ল":"¤","রু":"i“","রূ":"iƒ","ল্ক":"é","ল্গ":"ê","ল্প":"í","ল্ট":"ë","ল্ড":"ì","ল্ফ":"î","ল্ব":"j¦","ল্ম":"j¥","ল্ল":"jø","শু":"ï","শ্চ":"ð","শ্ন":"kœ","শ্ব":"k¦","শ্ম":"k¥","শ্ল":"kø","ষ্ক":"®‹","ষ্ক্র":"®Œ","ষ্ট":"ó","ষ্ঠ":"ô","ষ্ণ":"ò","ষ্প":"®ú","ষ্ফ":"õ","ষ্ম":"®§","স্ক":"¯‹","স্ট":"÷","স্খ":"ö","স্ত":"¯—","স্তু":"¯‘","স্থ":"¯’","স্ন":"mœ","স্প":"¯ú","স্ফ":"ù","স্ব":"¯^","স্ম":"¯§","স্ল":"¯","হু":"û","হ্ণ":"nè","হ্ন":"ý","হ্ম":"þ","হ্ল":"n¬","হৃ":"ü","র্":"©","্র":"«","্য":"¨","্":"&","আ":"Av","অ":"A","ই":"B","ঈ":"C","উ":"D","ঊ":"E","ঋ":"F","এ":"G","ঐ":"H","ও":"I","ঔ":"J","ক":"K","খ":"L","গ":"M","ঘ":"N","ঙ":"O","চ":"P","ছ":"Q","জ":"R","ঝ":"S","ঞ":"T","ট":"U","ঠ":"V","ড":"W","ঢ":"X","ণ":"Y","ত":"Z","থ":"_","দ":"`","ধ":"a","ন":"b","প":"c","ফ":"d","ব":"e","ভ":"f","ম":"g","য":"h","র":"i","ল":"j","শ":"k","ষ":"l","স":"m","হ":"n","ড়":"o","ঢ়":"p","য়":"q","ৎ":"r","০":"0","১":"1","২":"2","৩":"3","৪":"4","৫":"5","৬":"6","৭":"7","৮":"8","৯":"9","া":"v","ি":"w","ী":"x","ু":"y","ূ":"~","ৃ":"…","ে":"‡","ৈ":"‰","ৗ":"Š","ং":"s","ঃ":"t","ঁ":"u"};
var uni2somewherein_string_conversion_map={"।":"|","‘":"Ô","’":"Õ","“":"Ò","”":"Ó","্র্য":"ª¨","র‌্য":"i¨","ক্ক":"°","ক্ট":"±","ক্ত":"³","ক্ব":"K¡","স্ক্র":"¯Œ","ক্র":"µ","ক্ল":"K¬","ক্ষ":"¶","ক্স":"·","গু":"¸","গ্ধ":"»","গ্ন":"Mœ","গ্ম":"M¥","গ্ল":"M","গ্রু":"Mªy","ঙ্ক":"¼","ঙ্ক্ষ":"•¶","ঙ্খ":"•L","ঙ্গ":"½","ঙ্ঘ":"•N","চ্চ":"”P","চ্ছ":"”Q","চ্ছ্ব":"”Q¡","চ্ঞ":"”T","জ্জ্ব":"¾¡","জ্জ":"¾","জ্ঝ":"À","জ্ঞ":"Á","জ্ব":"R¡","ঞ্চ":"Â","ঞ্ছ":"Ã","ঞ্জ":"Ä","ঞ্ঝ":"Å","ট্ট":"Æ","ট্ব":"U¡","ট্ম":"U¥","ড্ড":"Ç","ণ্ট":"È","ণ্ঠ":"É","ন্স":"Ý","ণ্ড":"Ê","ন্তু":"š‘","ণ্ব":"Y^","ত্ত":"Ë","ত্ত্ব":"Ë¡","ত্থ":"Ì","ত্ম":"Z¥","ত্ন":"Zœ","ন্ত্ব":"š—¡","ত্ব":"Z¡","থ্ব":"_¡","দ্গ":"˜M","দ্ঘ":"˜N","দ্দ":"Ï","দ্ধ":"×","দ্ব":"˜¡","দ্ব":"Ø","দ্ভ":"™¢","দ্ম":"Ù","দ্রু":"`ª“","ধ্ব":"aŸ","ধ্ম":"a¥","ন্ট":"›U","ন্ড":"Û","ন্ত্র":"š¿","ন্ত":"š—","স্ত্র":"¯¿","ত্র":"Î","ন্থ":"š’","ন্দ":"›`","ন্দ্ব":"›Ø","ন্ধ":"Ü","ন্ন":"bœ","ন্ব":"š^","ন্ম":"b¥","প্ট":"Þ","প্ত":"ß","প্ন":"cœ","প্প":"à","প্ল":"c","প্স":"á","ফ্ল":"d¬","ব্জ":"â","ব্দ":"ã","ব্ধ":"ä","ব্ব":"eŸ","ব্ল":"e","ভ্র":"å","ম্ন":"gœ","ম্প":"¤ú","ম্ফ":"ç","ম্ব":"¤^","ম্ভ":"¤¢","ম্ভ্র":"¤£","ম্ম":"¤§","ম্ল":"¤","রু":"i“","রূ":"iƒ","ল্ক":"é","ল্গ":"ê","ল্ট":"ë","ল্ড":"ì","ল্প":"í","ল্ফ":"î","ল্ব":"j¦","ল্ম":"j¥","ল্ল":"j","শু":"ï","শ্চ":"ð","শ্ন":"kœ","শ্ব":"k¦","শ্ম":"k¥","শ্ল":"k","ষ্ক":"®‹","ষ্ক্র":"®Œ","ষ্ট":"ó","ষ্ঠ":"ô","ষ্ণ":"ò","ষ্প":"®ú","ষ্ফ":"õ","ষ্ম":"®§","স্ক":"¯‹","স্ট":"÷","স্খ":"ö","স্ত":"¯—","স্তু":"¯‘","স্থ":"¯’","স্ন":"mœ","স্প":"¯ú","স্ফ":"ù","স্ব":"¯^","স্ম":"¯§","স্ল":"¯","হ্ণ":"nè","হ্ন":"ý","হ্ম":"þ","হু":"û","হ্ল":"n¬","হৃ":"ü","র্":"©","্র":"Ö","্য":"¨","্":"&","আ":"Av","অ":"A","ই":"B","ঈ":"C","উ":"D","ঊ":"E","ঋ":"F","এ":"G","ঐ":"H","ও":"I","ঔ":"J","ক":"K","খ":"L","গ":"M","ঘ":"N","ঙ":"O","চ":"P","ছ":"Q","জ":"R","ঝ":"S","ঞ":"T","ট":"U","ঠ":"V","ড":"W","ঢ":"X","ণ":"Y","ত":"Z","থ":"_","দ":"`","ধ":"a","ন":"b","প":"c","ফ":"d","ব":"e","ভ":"f","ম":"g","য":"h","র":"i","ল":"j","শ":"k","ষ":"l","স":"m","হ":"n","ড়":"o","ঢ়":"p","য়":"q","ৎ":"r","০":"0","১":"1","২":"2","৩":"3","৪":"4","৫":"5","৬":"6","৭":"7","৮":"8","৯":"9","া":"v","ি":"w","ী":"x","ু":"y","ূ":"~","ৃ":"„","ে":"‡","ৈ":"‰","ৗ":"Š","ং":"s","ঃ":"t","ঁ":"u"};
var uni2boisakhi_string_conversion_map={"্র্য":"Ûø","র‌্য":"kø","ক্ক":"~","ক্ট":"ƒ","ক্ত":"£ß","ক্ব":"Kò","স্ক্র":"Ç","ক্র":"¢ß","ক্ষ্ম":"qô","ক্ষ":"q","ক্স":"…","ক্ল":"Kõ","গু":"†","গ্গ":"‡","গ্ধ":"ˆ","গ্ন":"Mí","গ্ম":"Mô","গ্ল":"Mö","ঙ্ক":"‰","ঙ্ক্ষ":"áq","ঙ্খ":"áL","ঙ্গ":"Š","ঙ্ঘ":"áN","চ্চ":"âP","চ্ছ":"âQ","চ্ছ্ব":"âQò","জ্জ্ব":"Œò","জ্জ":"Œ","জ্ঞ":"š","জ্ব":"Rò","ঞ্চ":"é","˜":"ঞ্ছ","ঞ্জ":"™","ঞ্ঝ":"ã","ট্ট":"›","ট্ব":"Uò","ট্ম":"Uô","ড্ড":"œ","ণ্ঠ":"Ÿ","ন্ঠ":"ª","ন্স":"Ý","ণ্ড":"¡","ন্তু":"š‘","ন্তু":"ìç","ণ্ব":"Yð","ত্ত্ব":"£ò","ত্থ":"¤","ত্ন":"Zí","ত্ম":"£ô","ত্ম":"Zô","ত্ত":"£","ন্ত্ব":"ìòæ","ত্ব":"Zò","থ্ব":"aò","দ্দ":"¥","দ্ধ":"¦","দ্ব":"§","দ্ভ":"¨","দ্ম":"bô","ধ্ব":"cµ","ন্ট":"ëU","ন্ট":"åU","ন্ড":"«","ন্ত্র":"ìè","ন্ত":"ìæ","স্ত্র":"þè","ত্র":"¢","ন্দ":"ëb","ন্দ্ব":"ë§","ন্ধ":"¬","ন্ধ":"ëc","ন্ন":"Ò","ন্ন":"dí","ন্ব":"ìñ","ন্থ":"ìÿ","ন্ম":"dô","ন্স":"ëo","প্ট":"ïU","প্ত":"®","প্ন":"eí","প্প":"¯","প্ল":"eö","ফ্ল":"d¬","ব্জ":"±","ব্দ":"²","ব্ধ":"³","ব্ব":"gµ","ব্ল":"gö","ম্ভ্র":"»","ভ্র":"¸","ম্ন":"ií","ম্প":"óe","ম্ফ":"óf","ম্ব":"¹","ম্ভ":"º","ম্ম":"ói","ম্ল":"óö","ল্ক":"¿","ল্গ":"ùM","ল্ট":"ùU","ল্ড":"À","ল্প":"ùe","ল্ফ":"ùf","ল্ব":"lð","ল্ম":"lô","ল্ল":"Á","শু":"Â","শ্চ":"úP","শ্ন":"mí","শ্ব":"mð","শ্ম":"mô","শ্ল":"mö","ষ্ক":"ûK","ষ্ক্র":"û¢ß","ষ্ট":"Ä","ষ্ঠ":"Å","ষ্প":"ûe","ষ্ফ":"üf","ষ্ম":"ûô","স্ক":"Æ","স্খ":"ýL","স্ট":"ýU","স্থ":"þÿ","স্ত":"þæ","স্তু":"þç","স্ন":"þí","স্প":"þe","স্ফ":"ýf","স্ব":"È","স্ব":"þñ","স্ম":"þô","হু":"É","হ্ণ":"pî","হ্ন":"pß","হ্ম":"Ê","হ্ল":"n¬","হ্ল":"põ","হৃ":"pÕ","ব":"ò","র্":"ê","্র":"Þ","্য":"ø","্":"z","আ":"Aw","অ":"A","ই":"B","ঈ":"C","উ":"D","ঊ":"E","ঋ":"F","এ":"G","ঐ":"H","ও":"I","ঔ":"J","ক":"K","খ":"L","গ":"M","ঘ":"N","ঙ":"O","চ":"P","ছ":"Q","জ":"R","ঝ":"S","ঞ":"T","ট":"U","ঠ":"V","ড":"W","ঢ":"X","ণ":"Y","ত":"Z","থ":"¤","দ":"b","ধ":"c","ন":"d","প":"e","ফ":"f","ব":"g","ভ":"h","ম":"i","য":"j","র":"k","ল":"l","শ":"m","ষ":"n","স":"o","হ":"p","ড়":"r","ঢ়":"s","য়":"t","থ":"a","ৎ":"u","ং":"v","ঁ":"^","০":"0","১":"1","২":"2","৩":"3","৪":"4","৫":"5","৬":"6","৭":"7","৮":"8","৯":"9","া":"w","ি":"x","ী":"y","ু":"×","ূ":"Ô","ৃ":"Ú","ে":"Ë","ৈ":"Ð","ৗ":"#","।":"„"};
function ReArrangeUnicodeText(str)
{var barrier=0;for(var i=0;i<str.length;i++)
{if(i<str.length&&IsBanglaPreKar(str.charAt(i)))
{var j=1;while(IsBanglaBanjonborno(str.charAt(i-j)))
{if(i-j<0)
break;if(i-j<=barrier)break;if(IsBanglaHalant(str.charAt(i-j-1)))
j+=2;else
break;}
var temp=str.substring(0,i-j);temp+=str.charAt(i);temp+=str.substring(i-j,i);temp+=str.substring(i+1,str.length);str=temp;barrier=i+1;continue;}
if(i<str.length-1&&IsBanglaHalant(str.charAt(i))&&str.charAt(i-1)=='র'&&!IsBanglaHalant(str.charAt(i-2)))
{var j=1;var found_pre_kar=0;while(true)
{if(IsBanglaBanjonborno(str.charAt(i+j))&&IsBanglaHalant(str.charAt(i+j+1)))
j+=2;else if(IsBanglaBanjonborno(str.charAt(i+j))&&IsBanglaPreKar(str.charAt(i+j+1)))
{found_pre_kar=1;break;}
else
break;}
var temp=str.substring(0,i-1);temp+=str.substring(i+j+1,i+j+found_pre_kar+1);temp+=str.substring(i+1,i+j+1);temp+=str.charAt(i-1);temp+=str.charAt(i);temp+=str.substring(i+j+found_pre_kar+1,str.length);str=temp;i+=(j+found_pre_kar);barrier=i+1;}}
return str;}
function ConvertToASCII(line)
{
var myRegExp;
myRegExp=new RegExp("ো","g");
line=line.replace(myRegExp,"ো");
myRegExp=new RegExp("ৌ","g");
line=line.replace(myRegExp,"ৌ");
line=ReArrangeUnicodeText(line);
for(var unic in uni2bijoy_string_conversion_map)
{
    myRegExp=new RegExp(unic,"g");
    line=line.replace(myRegExp,uni2bijoy_string_conversion_map[unic]);
}
return line;
}
function IsBanglaPreKar(CUni)
{if(CUni=='ি'||CUni=='ৈ'||CUni=='ে')
return true;return false;}
function IsBanglaBanjonborno(CUni)
{if(CUni=='ক'||CUni=='খ'||CUni=='গ'||CUni=='ঘ'||CUni=='ঙ'||CUni=='চ'||CUni=='ছ'||CUni=='জ'||CUni=='ঝ'||CUni=='ঞ'||CUni=='ট'||CUni=='ঠ'||CUni=='ড'||CUni=='ঢ'||CUni=='ণ'||CUni=='ত'||CUni=='থ'||CUni=='দ'||CUni=='ধ'||CUni=='ন'||CUni=='প'||CUni=='ফ'||CUni=='ব'||CUni=='ভ'||CUni=='ম'||CUni=='শ'||CUni=='ষ'||CUni=='স'||CUni=='হ'||CUni=='য'||CUni=='র'||CUni=='ল'||CUni=='য়'||CUni=='ং'||CUni=='ঃ'||CUni=='ঁ'||CUni=='ৎ')
return true;return false;}
function IsBanglaSoroborno(CUni)
{if(CUni=='অ'||CUni=='আ'||CUni=='ই'||CUni=='ঈ'||CUni=='উ'||CUni=='ঊ'||CUni=='ঋ'||CUni=='ঌ'||CUni=='এ'||CUni=='ঐ'||CUni=='ও'||CUni=='ঔ')
return true;return false;}
function IsBanglaHalant(CUni)
{if(CUni=='্')
return true;return false;}

and here is the c# code:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Test_Core_Functions
{
    public static class Test1
    {

        static Dictionary<string, string> ConversionMap = new Dictionary<string, string>
        {
            {"।", "|"},
            {"'", "Ô"},
            {"'", "Õ"},
            {"\"", "Ò"},
            {"\"", "Ó"},
            {"্র্য", "ª¨"},
            {"র‌্য", "i¨"},
            {"ক্ক", "°"},
            {"ক্ট", "±"},
            {"ক্ত", "³"},
            {"ক্ব", "K¡"},
            {"স্ক্র", "¯Œ"},
            {"ক্র", "µ"},
            {"ক্ল", "K¬"},
            {"ক্ষ", "¶"},
            {"ক্স", "·"},
            {"গু", "¸"},
            {"গ্ধ", "»"},
            {"গ্ন", "Mœ"},
            {"গ্ম", "M¥"},
            {"গ্ল", "M"},
            {"গ্রু", "Mªy"},
            {"ঙ্ক", "¼"},
            {"ঙ্ক্ষ", "•¶"},
            {"ঙ্খ", "•L"},
            {"ঙ্গ", "½"},
            {"ঙ্ঘ", "•N"},
            {"চ্চ", "\"P"},
            {"চ্ছ", "\"Q"},
            {"চ্ছ্ব", "\"Q¡"},
            {"চ্ঞ", "\"T"},
            {"জ্জ্ব", "¾¡"},
            {"জ্জ", "¾"},
            {"জ্ঝ", "À"},
            {"জ্ঞ", "Á"},
            {"জ্ব", "R¡"},
            {"ঞ্চ", "Â"},
            {"ঞ্ছ", "Ã"},
            {"ঞ্জ", "Ä"},
            {"ঞ্ঝ", "Å"},
            {"ট্ট", "Æ"},
            {"ট্ব", "U¡"},
            {"ট্ম", "U¥"},
            {"ড্ড", "Ç"},
            {"ণ্ট", "È"},
            {"ণ্ঠ", "É"},
            {"ন্স", "Ý"},
            {"ণ্ড", "Ê"},
            {"ন্তু", "š'"},
            {"ণ্ব", "Y^"},
            {"ত্ত", "Ë"},
            {"ত্ত্ব", "Ë¡"},
            {"ত্থ", "Ì"},
            {"ত্ন", "Zœ"},
            {"ত্ম", "Z¥"},
            {"ন্ত্ব", "š—¡"},
            {"ত্ব", "Z¡"},
            {"থ্ব", "_¡"},
            {"দ্গ", "˜M"},
            {"দ্ঘ", "˜N"},
            {"দ্দ", "Ï"},
            {"দ্ধ", "×"},
            {"দ্ব", "˜¡"},
            {"দ্ব", "Ø"},
            {"দ্ভ", "™¢"},
            {"দ্ম", "Ù"},
            {"দ্রু", "`ª\""},
            {"ধ্ব", "aŸ"},
            {"ধ্ম", "a¥"},
            {"ন্ট", "›U"},
            {"ন্ঠ", "Ú"},
            {"ন্ড", "Û"},
            {"ন্ত্র", "š¿"},
            {"ন্ত", "š—"},
            {"স্ত্র", "¯¿"},
            {"ত্র", "Î"},
            {"ন্থ", "š'"},
            {"ন্দ", "›`"},
            {"ন্দ্ব", "›Ø"},
            {"ন্ধ", "Ü"},
            {"ন্ন", "bœ"},
            {"ন্ব", "š^"},
            {"ন্ম", "b¥"},
            {"প্ট", "Þ"},
            {"প্ত", "ß"},
            {"প্ন", "cœ"},
            {"প্প", "à"},
            {"প্ল", "c"},
            {"প্স", "á"},
            {"ফ্ল", "d¬"},
            {"ব্জ", "â"},
            {"ব্দ", "ã"},
            {"ব্ধ", "ä"},
            {"ব্ব", "eŸ"},
            {"ব্ল", "e"},
            {"ভ্র", "å"},
            {"ম্ন", "gœ"},
            {"ম্প", "¤ú"},
            {"ম্ফ", "ç"},
            {"ম্ব", "¤^"},
            {"ম্ভ", "¤¢"},
            {"ম্ভ্র", "¤£"},
            {"ম্ম", "¤§"},
            {"ম্ল", "¤"},
            {"রু", "i\""},
            {"রূ", "iƒ"},
            {"ল্ক", "é"},
            {"ল্গ", "ê"},
            {"ল্প", "í"},
            {"ল্ট", "ë"},
            {"ল্ড", "ì"},
            {"ল্ফ", "î"},
            {"ল্ব", "j¦"},
            {"ল্ম", "j¥"},
            {"ল্ল", "jø"},
            {"শু", "ï"},
            {"শ্চ", "ð"},
            {"শ্ন", "kœ"},
            {"শ্ব", "k¦"},
            {"শ্ম", "k¥"},
            {"শ্ল", "kø"},
            {"ষ্ক", "®‹"},
            {"ষ্ক্র", "®Œ"},
            {"ষ্ট", "ó"},
            {"ষ্ঠ", "ô"},
            {"ষ্ণ", "ò"},
            {"ষ্প", "®ú"},
            {"ষ্ফ", "õ"},
            {"ষ্ম", "®§"},
            {"স্ক", "¯‹"},
            {"স্ট", "÷"},
            {"স্খ", "ö"},
            {"স্ত", "¯—"},
            {"স্তু", "¯'"},
            {"স্থ", "¯'"},
            {"স্ন", "mœ"},
            {"স্প", "¯ú"},
            {"স্ফ", "ù"},
            {"স্ব", "¯^"},
            {"স্ম", "¯§"},
            {"স্ল", "¯"},
            {"হু", "û"},
            {"হ্ণ", "nè"},
            {"হ্ন", "ý"},
            {"হ্ম", "þ"},
            {"হ্ল", "n¬"},
            {"হৃ", "ü"},
            {"র্", "©"},
            {"্র", "«"},
            {"্য", "¨"},
            {"্", "&"},
            {"আ", "Av"},
            {"অ", "A"},
            {"ই", "B"},
            {"ঈ", "C"},
            {"উ", "D"},
            {"ঊ", "E"},
            {"ঋ", "F"},
            {"এ", "G"},
            {"ঐ", "H"},
            {"ও", "I"},
            {"ঔ", "J"},
            {"ক", "K"},
            {"খ", "L"},
            {"গ", "M"},
            {"ঘ", "N"},
            {"ঙ", "O"},
            {"চ", "P"},
            {"ছ", "Q"},
            {"জ", "R"},
            {"ঝ", "S"},
            {"ঞ", "T"},
            {"ট", "U"},
            {"ঠ", "V"},
            {"ড", "W"},
            {"ঢ", "X"},
            {"ণ", "Y"},
            {"ত", "Z"},
            {"থ", "_"},
            {"দ", "`"},
            {"ধ", "a"},
            {"ন", "b"},
            {"প", "c"},
            {"ফ", "d"},
            {"ব", "e"},
            {"ভ", "f"},
            {"ম", "g"},
            {"য", "h"},
            {"র", "i"},
            {"ল", "j"},
            {"শ", "k"},
            {"ষ", "l"},
            {"স", "m"},
            {"হ", "n"},
            {"ড়", "o"},
            {"ঢ়", "p"},
            {"য়", "q"},
            {"ৎ", "r"},
            {"০", "0"},
            {"১", "1"},
            {"২", "2"},
            {"৩", "3"},
            {"৪", "4"},
            {"৫", "5"},
            {"৬", "6"},
            {"৭", "7"},
            {"৮", "8"},
            {"৯", "9"},
            {"া", "v"},
            {"ি", "w"},
            {"ী", "x"},
            {"ু", "y"},
            {"ূ", "~"},
            {"ৃ", "…"},
            {"ে", "‡"},
            {"ৈ", "‰"},
            {"ৗ", "Š"},
            {"ং", "s"},
            {"ঃ", "t"},
            {"ঁ", "u"}
        };

        static string ReArrangeUnicodeText(string str)
        {
            int barrier = 0;
            for(int i = 0; i < str.Length; i++)
            {
                if(i < str.Length && IsBanglaPreKar(str[i]))
                {
                    int j = 1;
                    while(IsBanglaBanjonborno(str[i - j]))
                    {
                        if(i - j < 0)
                            break;
                        if(i - j <= barrier)
                            break;
                        if(IsBanglaHalant(str[i - j - 1]))
                            j += 2;
                        else
                            break;
                    }
                    StringBuilder temp = new StringBuilder();
                    temp.Append(str.Substring(0, i - j));
                    temp.Append(str[i]);
                    temp.Append(str.Substring(i - j, j));
                    temp.Append(str.Substring(i + 1, str.Length - i - 1));
                    str = temp.ToString();
                    barrier = i + 1;
                    continue;
                }

                if(i < str.Length - 1 && IsBanglaHalant(str[i]) && str[i - 1] == 'র' && !IsBanglaHalant(str[i - 2]))
                {
                    int j = 1;
                    int found_pre_kar = 0;
                    while(true)
                    {
                        if(IsBanglaBanjonborno(str[i + j]) && IsBanglaHalant(str[i + j + 1]))
                            j += 2;
                        else if(IsBanglaBanjonborno(str[i + j]) && IsBanglaPreKar(str[i + j + 1]))
                        {
                            found_pre_kar = 1;
                            break;
                        }
                        else
                            break;
                    }
                    StringBuilder temp = new StringBuilder();
                    temp.Append(str.Substring(0, i - 1));
                    temp.Append(str.Substring(i + j + 1, i + j + 1 + found_pre_kar));
                    temp.Append(str.Substring(i + 1, j));
                    temp.Append(str[i - 1]);
                    temp.Append(str[i]);
                    temp.Append(str.Substring(i + j + 1 + found_pre_kar, str.Length - i - j - 1 - found_pre_kar));
                    str = temp.ToString();
                    i += (j + found_pre_kar);
                    barrier = i + 1;
                }
            }
            return str;
        }

        static bool IsBanglaPreKar(char CUni)
        {
            return CUni == 'ি' || CUni == 'ৈ' || CUni == 'ে';
        }

        static bool IsBanglaBanjonborno(char CUni)
        {
            return CUni == 'ক' || CUni == 'খ' || CUni == 'গ' || CUni == 'ঘ' || CUni == 'ঙ' || CUni == 'চ' || CUni == 'ছ' || CUni == 'জ' || CUni == 'ঝ' || CUni == 'ঞ' || CUni == 'ট' || CUni == 'ঠ' || CUni == 'ড' || CUni == 'ঢ' || CUni == 'ণ' || CUni == 'ত' || CUni == 'থ' || CUni == 'দ' || CUni == 'ধ' || CUni == 'ন' || CUni == 'প' || CUni == 'ফ' || CUni == 'ব' || CUni == 'ভ' || CUni == 'ম' || CUni == 'শ' || CUni == 'ষ' || CUni == 'স' || CUni == 'হ' || CUni == 'য' || CUni == 'র' || CUni == 'ল' || CUni.ToString() == "য়" || CUni == 'ং' || CUni == 'ঃ' || CUni == 'ঁ' || CUni == 'ৎ';
        }

        static bool IsBanglaHalant(char CUni)
        {
            if(CUni == '্')
                return true;
            return false;
        }

        public static string ConvertToASCII(string line)
        {
            line = Regex.Replace(line, "ো", "ো");
            line = Regex.Replace(line, "ৌ", "ৌ");
            line = ReArrangeUnicodeText(line);

            foreach(var unic in ConversionMap)
            {
                line = Regex.Replace(line, unic.Key, unic.Value);
            }

            return line;
        }

    }
}

i don't see any duplicate in the "ConversionMap" variable (in c#).. but when i try to execute the code, it throws following error:
C#:
An item with the same key has already been added.

any thought why this error comes up?

thanks in advance..
 
line 18 +19
 
Debugger should tell you which key, for example:
ArgumentException: An item with the same key has already been added. Key: দ্ব
Looks like line 77+78 in post 1.
 
This is not something you need to or should ask us about. You are just as capable of looking through that list as we are. If it was me, I would use Find & Replace to change each line of the collection initialiser to an Add call and then the exception(s) will be thrown on the exact key that is the issue. That would take a few minutes to test and fix.
 
Debugger should tell you which key, for example:

Looks like line 77+78 in post 1.

thanks a lot for your kind response sir, i am so pleased..

the issue is debugger does not tell me the exact key(s) where the issue is, and thus by human eye (as the key name is in unicode) was very hard for me to find out the issue/keys.

here is the full exception details:
C#:
System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Test_Core_Functions.Test1' threw an exception.
  Source=Test Core Functions
  StackTrace:
   at Test_Core_Functions.Test1.ConvertToASCII(String line) in D:\My Work\Visual Studio\E2019\NationWide\00 Common Project\Test Core Functions\Test1.cs:line 326
   at Test_Core_Functions.Form1.Uni2BijoyButton_Click(Object sender, EventArgs e) in D:\My Work\Visual Studio\E2019\NationWide\00 Common Project\Test Core Functions\Form1.cs:line 507
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Test_Core_Functions.Program.Main() in D:\My Work\Visual Studio\E2019\NationWide\00 Common Project\Test Core Functions\Program.cs:line 19

  This exception was originally thrown at this call stack:
    [External Code]
    Test_Core_Functions.Test1.Test1() in Test1.cs

Inner Exception 1:
ArgumentException: An item with the same key has already been added.

once again.. thanks a lot for your kind help/response/support

best regards
 
This is not something you need to or should ask us about. You are just as capable of looking through that list as we are. If it was me, I would use Find & Replace to change each line of the collection initialiser to an Add call and then the exception(s) will be thrown on the exact key that is the issue. That would take a few minutes to test and fix.

oh!. i am truly sorry and ask for your apology..

i have been working on that over 2 days, and didn't find a solution as the debugger/IDE not telling me which key is duplicate. And also as the dictionary is inline constructed so, i was not able to find a way to split the keys and add one by one to see which one is duplicate..

and also as this forum is so helpful and rather bullying on why the poster post the question, it (it's users) does try theirs best to help out the poster. that's why i dare to post this question/thread.

though yes.. as i have do some google search before posting it.. but still i am sorry and should be more cautious next time..

nevertheless thanks for your response though..

best regards
 
Lines 15-234 can be converted to Add() commands by taking advantage of the editors search and replace with regular expressions.


Alternative, it might be easier to just change the Dictionary<string,string> declared on line 13 to a list List<Tuple<string,string>>. Then you can iterate over the list and add into an initially empty dictionary and watch of the exceptions. When the exceptions get thrown, you have a duplicate key.
 
Lines 15-234 can be converted to Add() commands by taking advantage of the editors search and replace with regular expressions.


Alternative, it might be easier to just change the Dictionary<string,string> declared on line 13 to a list List<Tuple<string,string>>. Then you can iterate over the list and add into an initially empty dictionary and watch of the exceptions. When the exceptions get thrown, you have a duplicate key.

thanks a lot.. for your suggestion..
 
Back
Top Bottom