CST1801 Visual Basic I
Lab Week 11


Regular Expressions

Although the following exercises can be solved using midstring functions, these labs are solved best using regular expressions.  Below are a couple of websites that have a library of regular expressions and online testers.

Regular Expression Library.

Regular Expression online tester.

 

Exercises

Exercise PhoneParse (10 points)

Write a program that accepts a 10 digit phone number.  3 digits for the area code, 3 digits for the exchange, and 4 digits for the local.

Parse the phone number in such a way that the user has flexibility for entering the number in many of the common forms in use today.

Examples:
(320) 555-1212
320-555-1212
320 555 1212
320.555.1212

Hint:
Read the input as a string from a textbox.  Convert the string to a character array.  Parse the character array OR use regular expressions.

  Result (Save to your local machine and run) 
 

Exercise NumberString (10 points)

Write a  program which allows input of the form:

12 + 345 - 44 - 23 - 57 + 2345

can be handled.  Assume that the user will make no error in entering the string of numbers and operators.  The operators are limited to be only addition and subtraction.

Hint: The patter of such input is an initial number, followed by any number of operator/number pairs.  Your program should handle the initial number, then loop to handle the following pairs of operators and numbers.

  Result (Save to your local machine and run) 

 

Hint: Here is the solution.  Notice that the
Imports System.Text.RegularExpressions

Statement had to be manually added to the code.

Ex16_6 solution.