如何在Windows应用程序中使用c#将文本英语转换为印地文? [英] How to convert text english to hindi using c# in windows Application?
本文介绍了如何在Windows应用程序中使用c#将文本英语转换为印地文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友,
如何在Windows应用程序中使用c#将文本英语转换为印地文?通过创建自定义字体或代码?
问候
Swapnil BAdgujar
解决方案
< blockquote>尝试谷歌 [ ^ ]了解如何入门。
使用System;
使用System.Net;
使用System.Text;
使用System.Text.RegularExpressions;
命名空间实用工具
{
公共静态类翻译器
{
///< summary>
///翻译文本。
///
///< param name =input/>输入。
///< param name =languagePair/>语言对。
///< returns>
public static string TranslateText(string input,string languagePair)
{
return TranslateText (输入,languagePair,System.Text.Encoding.UTF7);
}
///< summary>
///使用Google翻译翻译文字
///
///< param name =input/>您要翻译的字符串
///< param name =languagePair/> 2个字母语言对,由|分隔。
///例如en | da语言对意味着从英语翻译成丹麦语
///< param name =encoding/>编码。
/// < returns>转换为字符串
public static string TranslateText(string input,string languagePair,Encoding encoding)
{
string url = String .Format(http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1},输入,languagePair);
string result = String.Empty;
使用(WebClient webClient = new WebClient())
{
webClient.Encoding = encoding;
result = webClient.DownloadString(url);
}
匹配m = Regex.Match(结果,(?< =)(。*?)(?=));
if(m.Success)
result = m.Value;
return结果;
}
}
}
Hi Friends,
How to convert text english to hindi using c# in windows Application? by creating a custom font or code ?
Regards
Swapnil BAdgujar
解决方案
Try google[^] for ideas on how to get started.
using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace Utilities
{
public static class Translator
{
/// <summary>
/// Translates the text.
///
/// <param name="input" />The input.
/// <param name="languagePair" />The language pair.
/// <returns>
public static string TranslateText(string input, string languagePair)
{
return TranslateText(input, languagePair, System.Text.Encoding.UTF7);
}
/// <summary>
/// Translate Text using Google Translate
///
/// <param name="input" />The string you want translated
/// <param name="languagePair" />2 letter Language Pair, delimited by "|".
/// e.g. "en|da" language pair means to translate from English to Danish
/// <param name="encoding" />The encoding.
/// <returns>Translated to String
public static string TranslateText(string input, string languagePair, Encoding encoding)
{
string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
string result = String.Empty;
using (WebClient webClient = new WebClient())
{
webClient.Encoding = encoding;
result = webClient.DownloadString(url);
}
Match m = Regex.Match(result, "(?<=)(.*?)(?=)");
if (m.Success)
result = m.Value;
return result;
}
}
}
这篇关于如何在Windows应用程序中使用c#将文本英语转换为印地文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文