日本語の文字を英語の文字に変換するプログラムを作成しようとしていますが、私は奇妙な問題があり、どのように解決するのかわかりませんしかし、。私は、データセットを使用していると私は私の問題は、それが特定の文字を変換したくないということであり、それは変換したくない文字が文字にifとelse ifの問題C#
を変換するには、このコードを使用してい
私はここで設定した内容に基づいて:
// Sets fromtype to the type the character(s) currently is/are
string fromtype = "";
if (CharacterTable.Select("Romaji like '%" + character + "%'") != null)
{
fromtype = "Romaji";
}
else if (CharacterTable.Select("Hiragana like '%" + character + "%'") != null)
{
fromtype = "Hiragana";
}
else if (CharacterTable.Select("Katakana like '%" + character + "%'") != null)
{
fromtype = "Katakana";
}
私は「あれば」、それは私がそれを設定した場合、ローマ字文字を認識したくないために、すべての個々の行を変更した場合にのような今、「他にあれば」、それを見る。
DataSet CharacterDatabase = new DataSet();
DataTable CharacterTable = CharacterDatabase.Tables.Add();
//-- Add columns to the data table
CharacterTable.Columns.Add("Romaji", typeof(string));
CharacterTable.Columns.Add("Hiragana", typeof(string));
CharacterTable.Columns.Add("Katakana", typeof(string));
//-- Add rows to the data table
CharacterTable.Rows.Add("a", "?", "?");
// Sets fromtype to the type the character(s) currently is/are
string fromtype = "";
if (CharacterTable.Select("Romaji like '%" + character + "%'") != null)
{
fromtype = "Romaji";
}
else if (CharacterTable.Select("Hiragana like '%" + character + "%'") != null)
{
fromtype = "Hiragana";
}
else if (CharacterTable.Select("Katakana like '%" + character + "%'") != null)
{
fromtype = "Katakana";
}
// generates a new variable to store the return in
DataRow[] filteredRows = CharacterTable.Select(fromtype + " like '%" + character + "%'");
// Return the converted character in the requested type
foreach (DataRow row in filteredRows)
{
if (RequestedCharType == 1)
{
return row["Romaji"].ToString();
}
if (RequestedCharType == 2)
{
return row["Hiragana"].ToString();
}
if (RequestedCharType == 3)
{
return row["Katakana"].ToString();
}
}
// if it couldn't find the character, return the original character
return character;
あなた自身の質問を解決したようです。残っている問題があればそれは何ですか? – ziesemer
残っている問題は、私が使用しているかどうかにかかわらず、私が使用しているかどうかは、変換しない何か、いつも理由を理解するために愚かです。 – user1071461
すべてのIfsを使用すると、あなたの最初のIfを見つける別のIfに落ちて、そこでは "fromtype"の値も設定します。私はあなたが使っているこのCharacterTableにあまり慣れていませんが、ローマ字、ひらがな、カタカナの3つの配列またはリストを持つだけで、より正確な結果を得るかもしれないと思っています。キャラクターは決定的な==であり、「好き」ではない。これらの配列やリストがどれくらい小さいかという理由で、パフォーマンス上の問題はありません。 – CptSupermrkt