0% found this document useful (0 votes)
4 views

complete-reference-vb_net_35

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

complete-reference-vb_net_35

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The .

NET Framework Regex Metalanguage

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:

Private Function StripNoise(ByVal sentence As String) As String


While x <= UBound(noiseArray)
sentence = Regex.Replace(sentence, noiseArray(x), "")
x += 1
End While
Return sentence
End Function

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.

File, Stream, and Text IO Operations


The .NET Framework provides an impressive range of IO namespaces that contain dozens of classes used for
writing, reading, and streaming all manner of text, characters, and binary data, as well as file, folder, and path
support. Many of them, such as those represented by the System.IO, System.Text, and System.XML
namespaces, let you code asynchronous and synchronous reading and writing of data to streams and files. All
these namespaces are currently partitioned across the mscorlib, System, System.Text, and System.XML
assemblies.

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

You might also like