[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1135
  • Last Modified:

Check if the word is in alphabetical letters

Hi all

I am hoping that someone can help me on how could I check in C# if the string is in alphabetical letters or not. For example if I have this string ( Moku????ina) or (0 ft )

Is there is a statement which could help me to do that?

And is this statement will consider the word which ends with question mark (i.e the last word in the question)

Thanks in advance for your help
Suzan
0
suzan_
Asked:
suzan_
1 Solution
 
jandromedaCommented:
You can use regular expressions to do this.
0
 
Fernando SotoCommented:
Hi suzan_;

As jandromeda stated you can use Regular Expressions. If you can give a spec on what you want to accept as a valid string I can give a Regex pattern that will work. For example you say ? at the end is valid does that also mean a . is also valid at the end and hyphenated words?

Fernando
0
 
suzan_Author Commented:
thanks both for the help

Fernando

? . ,  " (i.e all the punctuation) which ends the words are valid

But the punctuations or numbers in the beginning or within the word are not valid
thanks again for your help
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
mkosbieCommented:
If I understand correctly, you want to make sure a given string contains all words made up of letters with an optional punctuation mark at the end of each word?  The code below will do this.  Here's some sample output:

laksjdf? jakdsj" dkjfd.  <==== Passes validation
?alsdkfja asdlkfj <==== Does not pass
asdf <=== Passes validation
    private bool ValidateString(string input)
    {
        Regex r = new Regex("^([a-z]+[?!\"',.;:]?\\s+)*([a-z]+[?!\"',.;:]?\\s*)$", RegexOptions.IgnoreCase);
        return r.IsMatch(input);
    }

Open in new window

0
 
suzan_Author Commented:
thanks a lot mkosbie
this really help
0
 
mkosbieCommented:
Glad to help.
0
 
suzan_Author Commented:
mkosbie
or could someone help me with this

Regex r = new Regex("^([a-z]+[?!\"',.;:]?\\s+)*([a-z]+[?!\"',.;:]?\\s*)$", RegexOptions.IgnoreCase);

how can I  make for example
He's  << pass validation
"hi  << pass validation
(hi << pass validation
%hi << do not pass validation
so certain punctuation pass the validation

thanks again for help
suzan
0
 
mkosbieCommented:
1) What punctuation do you want to be valid at the end of the word
2) What punctuation do you want to be valid inside of the word
3) What punctuation do you want to be valid at the beginning of the word

Answer those and I'll redesign the expression accordingly.

You might consider using RegEx buddy (http://www.regexbuddy.com/) to help make expressions.
0
 
suzan_Author Commented:
thanks for replying

the valid punctuation

1- beginning of the word    " ( ' -
2- inside of the word   '  only before the last letter
                                    -  any where inside the word
3- end of the word  ! . , : ; " ) ' ? &  -


I really appreciate your help, thanks again
suzan
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now