I need some help with homework

Jan 16, 2022
Reaction score
I have homework due tomorrow, and I am a bit stuck on how to do it. It goes as following: i need to write a program in c#, that will write out the words in a string, that don't include numbers and stuff. For example: I write in : Hi I am Marko Co0l3r ye! and the program writes out: 3: Hi i am

I hope i'm clear and hopefully someone can offer some guidance and help
Mar 3, 2021
Reaction score
Sorry for the late reply! I'll try to check back around 1PM EST if you need more help. In general, please add what you've done so far, what doesn't make sense, what does, etc, so we can help lead rather than give you the answer. First, why didn't "Marko" match? Anyway...

You'll want to use the String.Split function to get the words out of the string.

Next, it's tough to say. I'd resort to regular expressions, as I'm not 100% sure what characters are allowed or not. A regular expression can either match the entire string with stuff that's allowed (i.e., whitelisting characters) or try to find characters that aren't allowed (i.e., blacklisting). It sounds like there's a more well-defined set of characters that are allowed, so let's whitelist them.

Let's try the IsMatch function. There's an example of how to create a new Regex object and call the function on a string on that page itself. The actual regex part is a bit harder. I'll be a little more explicit here because it can get rough. I'll put the full regex below, but here's how it's composed. We'll want to match entire string, from start to end, so we'll start the regex with "^" and end it with "$". Next, we'll want only alphabetic characters, lowercase or uppercase, "[a-zA-Z]". Lastly, we'll want one or more of those characters, so we'll follow that up with a "+". Finally, we have @"^[a-zA-Z]+$". If a word matches that, then it's good to print.

Give all that a try. If something doesn't make sense or you need further guidance, let me know. I'll try to check back midday.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads