c# - String, word to word translation -
i have class as
class dictonary { public string english{get;set;} public string hindi{get;set;} } here have list of class dictionary list<dictionary> having meaning in english , hindi. want function
public string engtohindi(string english) { private string hindi=""; //nepali = english =>logic goes here return hindi; } if pass string "my name manoj." must return "mera naam hai manoj"
list<dictionary> have data data as
english hindi --------------------- mera hai name naam
use dictionary class. works perfect. complete program can use. it's easy , define whole line!! happy coding! ;)
class program { private static dictionary<string, string> mydictionary; static void main(string[] args) { // initialize dictionary mydictionary = new dictionary<string, string>(); // fill dictionary // should fill if file or database or something! mydictionary.add("my", "mera"); mydictionary.add("is", "hai"); mydictionary.add("name", "naam"); // line want define in english: string line = "my name shamim"; // output defined line in hindi: string output = englinetohindi(line); console.writeline(output); console.readkey(); } static string englinetohindi(string line) { // array of words: string[] words = line.split(' '); string toreturn = ""; foreach (string word in words) { string temp = engtohindi(word) + " "; toreturn += temp; } return toreturn; } static string engtohindi(string engword) { string key1 = engword; // if not has meaning return same word! if (!mydictionary.containskey(key1)) return engword; else return mydictionary[key1]; } }
Comments
Post a Comment