Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write a function which will accept a Marathi text as input and convert the marathi text into unicode code Eg: My input to function will be
मी लाइक आहे
to
092E094000200932093E090809150020090609390947


Thank you in advance
Posted
Updated 22-Oct-22 5:48am

try this
pass parameter(true,true)
code--------

string marathi = "मी लाइक आहे";
UnicodeEncoding ue = new UnicodeEncoding(true,true);
string s1 = BitConverter.ToString(ue.GetBytes(marathi.ToCharArray())).Replace("-", "");


output
092E094000200932093E090709150020090609390947
 
Share this answer
 
Comments
EliteBrain 15-Mar-14 6:50am    
Superb Code Just 2 line and answered
SOHAM_GANDHI 15-Mar-14 6:52am    
thank you. for accepting answer
byte[] array1 = Encoding.UTF32.GetBytes(txtMarathiText.Text);

        string unicodeString = Encoding.Unicode.GetString(array1);
        System.Globalization.TextElementEnumerator enumerator =
            System.Globalization.StringInfo.GetTextElementEnumerator(unicodeString);
       
        StringBuilder sb = new StringBuilder();
        while (enumerator.MoveNext())
        {
            string s = enumerator.GetTextElement();
            int i = Char.ConvertToUtf32(s, 0);

            sb.Append(string.Format("{0:X}", i.ToString()));
           
        }

        lblresult.Text = sb.ToString();


But its giving me
92E094000200932093E09080915020090609390947
instead of
092E094000200932093E090809150020090609390947
its not showing 0 at ist position and 0 after 150
I thing string.format() is wrong......can some one help me regarding this

Thank you
 
Share this answer
 
Comments
Bernhard Hiller 14-Mar-14 6:15am    
sb.Append(string.Format("{0:X}", i.ToString())) - why do you use i.ToString()? Use i only.
Try this code statements
Code

string marathi = "मी लाइक आहे";
UnicodeEncoding ue = new UnicodeEncoding();
string s1 = BitConverter.ToString(ue.GetBytes(marathi.ToCharArray())).Replace("-", "");
MessageBox.Show(s1);


Output

2E094009200032093E09070915092000060939094709
 
Share this answer
 
Comments
EliteBrain 15-Mar-14 5:27am    
Hi Soham Thanks for you reply
You code does not give the desired output i need unicode in the format (Example: U+0061 U+4e2d U+042f)
After converting the unicode Character(Marathi)मी लाइक आहे we should get output 092E094000200932093E090709150020090609390947
you can check it on unicode converter website http://www.branah.com/unicode-converter
SOHAM_GANDHI 15-Mar-14 6:06am    
just change the code, pass parameter (true, true)
SOHAM_GANDHI 15-Mar-14 6:06am    
i'modified code, just check it
--guys here is the solution--plz accept it as solution--Thanks

public string GetUnicodeFromUnicodeString(string inputStr)
{
StringBuilder sb;
try
{
byte[] byteArray = Encoding.UTF32.GetBytes(inputStr);

string unicodeString = Encoding.Unicode.GetString(byteArray);

System.Globalization.TextElementEnumerator textenumerator =
System.Globalization.StringInfo.GetTextElementEnumerator(unicodeString);

sb = new StringBuilder();


while (textenumerator.MoveNext())
{

string s = textenumerator.GetTextElement();
int i = Char.ConvertToUtf32(s, 0);


if (s != "\0")
{
sb.Append(string.Format("{0:X4}", i));
//sb.Append(string.Format("{0} {1:x4}",s, i));
}
}

}
catch (Exception ex)
{

throw ex;
}

return sb.ToString();
}
 
Share this answer
 
मी लाईक आहे
हे अशुद्ध मराठी आहे
मी पसंती देतो, माझी पसंती आहे वगैरे
मराठी आधी बरोबर लिहावे
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900