如何删除任何给定句子中每个单词中的连续元音? [英] How to remove consecutive vowels in each word in the any given sentence?
本文介绍了如何删除任何给定句子中每个单词中的连续元音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
可以告诉我解决这个问题的最佳方法。
假设我有句话,比如,
I / P:richaard的甜蜜苏醒
我我需要在c#中编写一个程序,将连续的元音(a,e,i,o,u)移到给定句子的每个单词中的单个对应元音中,以便输出像
O / P:由richard演唱的歌曲。
我尝试过的事情:
类程序
{
static void Main(string [] args)
{
string inputString = Console.ReadLine();
string outputString = RemoveVowels(inputString);
Console.WriteLine(outputString);
Console.ReadKey();
}
静态字符串RemoveVowels(string inputString)
{
string tmpStr =,retStr =;
string [] splitStr = inputString.Split(Convert.ToChar());
foreach(在splitStr中的var字)
{
tmpStr = word.Replace(aa,a)。替换(ee,e)。替换(ii , I。)替换( OO, O UU U))替换(;
if(retStr ==)
{
retStr = tmpStr;
}
其他
{
retStr + =+ tmpStr;
}
}
返回retStr;
}
}
解决方案
我使用正则表达式:
< pre lang =c#> public static Regex multipleVowels = 新正则表达式( ([AEIOUaeiou])\\\\ {1,},RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
public static string regexReplace =
+;
...
string result = multipleVowels.Replace(InputText,regexReplace);
static string RemoveVowels( string inputString)
{
string outoputString = string .Empty;
char last = ' ?'跨度>;
foreach ( char c in inputString)
{
if (c == last)
{
开关(c)
{
case ' < span class =code-string> a':
case ' e':
case ' i':
case ' o':
case ' u':
break 跨度>;
默认:
outoputString + = c;
break ;
}
}
其他
outoputString + = c;
last = c;
}
return outoputString;
}
Hi All,
can any one tell me best approach to solve this problem.
Suppose I have sentence like,
I/P:"sweet soong suung by richaard"
I need to write a program in c# to remove consecutive vowels(a,e,i,o,u) into single corresponding vowel in each word of the given sentence to bring output like
O/P :"Swet song sung by richard".
What I have tried:
class Program { static void Main(string[] args) { string inputString = Console.ReadLine(); string outputString = RemoveVowels(inputString); Console.WriteLine(outputString); Console.ReadKey(); } static string RemoveVowels(string inputString) { string tmpStr = "",retStr=""; string[] splitStr = inputString.Split(Convert.ToChar(" ")); foreach (var word in splitStr) { tmpStr = word.Replace("aa", "a").Replace("ee","e").Replace("ii","i").Replace("oo","o").Replace("uu","u"); if (retStr == "") { retStr = tmpStr; } else { retStr += " " + tmpStr; } } return retStr; } }
解决方案
I'd use a regex:
public static Regex multipleVowels = new Regex("([AEIOUaeiou])\\1{1,}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled); public static string regexReplace = "
+"; ... string result = multipleVowels.Replace(InputText,regexReplace);
static string RemoveVowels(string inputString) { string outoputString = string.Empty; char last = '?'; foreach (char c in inputString) { if (c == last) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': break; default: outoputString += c; break; } } else outoputString += c; last = c; } return outoputString; }
这篇关于如何删除任何给定句子中每个单词中的连续元音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文