Click here to Skip to main content
12,818,664 members (30,459 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 2 Jul 2014

How to Convert between Romaji and Hiragana/Katakana

, 2 Jul 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
This is a dirtiest trick that shows you how to convert text between Romaji and Hiragana/Katakana


Few years ago, when I developed a Japanese translation tool, I realized that user may not have a Japanese IME on their PC, so they cannot input a Japanese Text in my tool's textbox. Then, I wrote a method to convert between Romaji and Kana. The trick is about how I made my database (the order is the most important).

Using the Code

First, declare a List to store database:

private List<string> Database = new List<string>();

Convert Mode enum:

enum Mode

Read data from text file:

private void GetDatabase()
    using (System.IO.StreamReader sr = new System.IO.StreamReader("Database.txt"))
        while (!sr.EndOfStream)
            string splitMe = sr.ReadLine();

Convert method:

private string Convert(string text, Mode convertMode)
    text = text.ToLower();
    string roma = string.Empty;
    string hira = string.Empty;
    string kata = string.Empty;
    foreach (string row in Database)
        var split = row.Split('@');
        roma = split[0];
        hira = split[1];
        kata = split[2];
        switch (convertMode)
            case Mode.Romaji:
                text = text.Replace(hira, roma);
                text = text.Replace(kata, roma.ToUpper());
            case Mode.Hiragana:
                text = text.Replace(roma, hira);
            case Mode.Katakana:
                text = text.Replace(roma, kata);
    return text;

Points of Interest

This is a very simple code. Please download the source code and use this method when you have to deal with Japanese input. :)

EDIT: Thanks to Seishin#, I updated my code.


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


About the Author

Software Developer (Junior)
Vietnam Vietnam
No Biography provided

You may also be interested in...

Comments and Discussions

Questionpossible modifications Pin
Seishin#3-Jul-14 5:00
memberSeishin#3-Jul-14 5:00 
AnswerRe: possible modifications Pin
Nguyen.H.H.Dang3-Jul-14 5:37
professionalNguyen.H.H.Dang3-Jul-14 5:37 
BugImage missing Pin
Akhil Mittal3-Jul-14 1:07
mvpAkhil Mittal3-Jul-14 1:07 
GeneralRe: Image missing Pin
Nguyen.H.H.Dang3-Jul-14 1:52
professionalNguyen.H.H.Dang3-Jul-14 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 3 Jul 2014
Article Copyright 2014 by Nguyen.H.H.Dang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid