65 660
Assignments Done
99,2%
Successfully Done
In October 2018

Answer to Question #62923 in C# for Peter

Question #62923
I want the user to enter a word in my application, but I want it to follow these rules:

• Word starts with a vowel
• Has a length of 5 – 8 characters
• Must have at least 1 repeating letter

How can I check for these in my program? (not case sensitive)
Expert's answer
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
class Program
{
static bool CheckInput(string s)
{
Regex r = new Regex(@"^[aeiouy]\w{4,7}$", RegexOptions.IgnoreCase);
Match match = r.Match(s);
return (match.Success && Regex.IsMatch(match.Value, @"(\w)(\w)*\1+"));
}
static void Main(string[] args)
{
Console.WriteLine("Write a word: ");
string s = Console.ReadLine();
if (CheckInput(s)) Console.WriteLine("Everything OK!");
else Console.WriteLine("Something is wrong!");
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions