complete-reference-vb_net_35
complete-reference-vb_net_35
Regex
This simple example shows how to use the Regex.Replace method when a match is found in the target that is
being parsed. The StripNoise method looks in a String for all instances of words provided in the array of
samples and then deletes the matches from the target String:
The method then returns the new String minus the matched words. Trying to use one of the String
manipulation methods or functions in an extensive block of text or a stream of characters would be extremely
difficult, and in many cases not at all possible.
You would also use regular expressions to parse complex TCP/IP headers to locate and remedy malformed
URLs. You know how complex some of these headers can be. If you need to look for misplaced periods,
white spaces, illegal characters, duplication of @ ("at") symbols, and so on, nothing other than a regular
expression can do the job for you. I also use it to "scrub" data and "prepare" complex search Strings supplied
against the likes of the Microsoft Index Server search engine, which chokes on a comma or a period or
misplaced white space.
The files you work with in your programs are typically ordered collections of bytes, representing characters
on a file system. Files are static; they squat on your hard disks like chickens hatching eggs. Streams, on the
other hand, are continuous "rivers" of data, writing to and reading from various devices. Streams are
constantly on the move.
Streams typically originate from files on devices like hard disks, CDs, and DVDs, and other devices for
persistent storage such as tape drives and optical disks. Streaming data moves across processes and
workspaces on your workstation, and between computers on the vast networks of the world. They move from
persistent memory into volatile memory and back again in a constant ebb and flow of data. Eventually,
streams of data get fed to printers for physical representation like annual reports or user manuals (after some
time, the pages can be fashioned into paper airplanes and tossed out of windows or shredded when the FBI
comes knocking).
The following is a list of the key sections we will discuss that facilitate basic I/O for the .NET Framework:
• File and Directories This section presents the classes that encapsulate the functionality of all known
file and directory processing operations. Files are opened, closed, and manipulated using the classes
519