Click here to Skip to main content
12,297,275 members (62,844 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hello,

I Wanted to Convert Devanagari Numbers to Numbers and vice-verse,
I'm using following

public static string ToNumberString(string num)
{
    string[] devNumbers = { "१", "२", "३", "४", "५", "६", "७", "८", "९", "०" };
    string[] numbers = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
    string strReplaced = num;
 

    int i;
    for (i = 0; i < devNumbers.Length; i++)
    {
        strReplaced = strReplaced.Replace(devNumbers[i], numbers[i]);
    }
    return strReplaced;
}
 
public static string ToDevnagariNumberString(string num)
{
    string[] devNumbers = { "१", "२", "३", "४", "५", "६", "७", "८", "९", "०" };
    string[] numbers = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
    string strReplaced = num;
 

    int i;
    for (i = 0; i < devNumbers.Length; i++)
    {
        strReplaced = strReplaced.Replace(numbers[i], devNumbers[i]);
    }
    return strReplaced;
}

Well, the code above works fine,

Is there a way to use above code to display and use Devanagari Numbers in DateTimePicker or any workaround for same,
also I'm using Numbers converted to Devanagari Numbers in DataGridView, how to convert them to Numbers and SORT and convert back to Devanagari Numbers
Posted 13-Feb-13 4:37am
Comments
CHill60 13-Feb-13 10:59am
   
Can't answer your first point, but on the sorting could you load the equivalent converted numbers to a non-visible column in the DataGridView and sort on that column rather than the Devanagari displayed column
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi
Here is an elegant way of doing it.

private Dictionary<int, string> m_devanagari;
 
public void InitialiseDevanagari()
{
    m_devanagari = new Dictionary<int, string>();
 
    int count = 1;
    m_devanagari.Add(count++, "१");
    m_devanagari.Add(count++, "२");
    m_devanagari.Add(count++, "३");
    m_devanagari.Add(count++, "४");
    m_devanagari.Add(count++, "५");
    m_devanagari.Add(count++, "६");
    m_devanagari.Add(count++, "७");
    m_devanagari.Add(count++, "८");
    m_devanagari.Add(count++, "९");
    m_devanagari.Add(count++, "०");
}
 
public int GetNumberFromDevanagari(string devanagariNumber)
{
    var result = m_devanagari.FirstOrDefault(item => item.Value.Equals(devanagariNumber));
    return result.Key;
}
 
public string GetDevanagariFromNumber(int number)
{
    var result = m_devanagari.FirstOrDefault(item => item.Key.Equals(number));
    return result.Value;
}
 
private void populateDataGrid()
{
    var devanagariArray = from row in m_devanagari select new { Number = row.Key, Devanagari = row.Value };
    dataGridView1.DataSource = devanagariArray.ToArray();
}


To use this on the DateTime picker, you may have to owner draw the individual date boxes, have look at this link below.

Windows Hijri Calendar[^]


I hope this helps.

Regards
Jegan
  Permalink  
Comments
Firdaus Shaikh 13-Feb-13 13:22pm
   
Hello Jegan,
Thanks for above code, Let me try and If this works I'll accept it as answer,
By the way


int count = 0;
m_devanagari.Add(count++, "०"); //This will take value zero
m_devanagari.Add(count++, "१");
m_devanagari.Add(count++, "२");
m_devanagari.Add(count++, "३");
m_devanagari.Add(count++, "४");
m_devanagari.Add(count++, "५");
m_devanagari.Add(count++, "६");
m_devanagari.Add(count++, "७");
m_devanagari.Add(count++, "८");
m_devanagari.Add(count++, "९");


Thanks,
Firdaus Shaikh
Firdaus Shaikh 13-Feb-13 14:13pm
   
System.Globalization contains 16 Calendars including HijriCalendar
but not devanagari
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi

Yes That's correct, I missed that "0" bit out. Regarding the calendar, then you may have to owner draw. See this article

Another Month Calendar[^]

Regards
Jegan
  Permalink  
Comments
Firdaus Shaikh 12-Mar-13 3:24am
   
Hello Jegan Thiyagesan,
Sorry for late reply,

I'll give it a try and if solves my problem, I'll accept your suggestion as solution,
Thanks by the way,
Firdaus Shaikh

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100