0% found this document useful (0 votes)
9 views1 page

Complete-Reference-Vb Net 31

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Complete-Reference-Vb Net 31

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Replace

sBuilder.Remove(5, 7)
Console.WriteLine(sBuilder)

Replace

Use the Replace method to replace characters within the StringBuilder object with other specified characters.
This example uses the Replace method to search a StringBuilder object for all instances of the exclamation
point character (!) and replace them with the question mark character (?):

Dim sBuilder As New StringBuilder("Hello Ariel!")


sBuilder.Replace("!"c, "?"c)
Console.WriteLine(sBuilder)

See anything you like in the preceding methods? In the following code for an Index Server application, I used
a StringBuilder object inside a While loop (this was later implemented with a regular expression). I extracted
the date information as previously described and then flushed the builder for the next iteration of the loop.
Once the entire table is built, the structure is dispatched, lock, stock, and barrel, to an awaiting Web client.

While row <= rows


rownum += 1 'this comes first because we use it in the HTML table
pRow = CType(rowIterator.Current, DataRow) 'get the row
TABLE1.Rows(row).Cells(0).InnerText = CStr(rownum) & "."
TABLE1.Rows(row).Cells(1).InnerText = pRow(2).ToString
TABLE1.Rows(row).Cells(2).InnerText = pRow(3).ToString
'extract a short date from the spaghetti _
'date sent by the index server
For intI = 0 To pRow(4).ToString.LastIndexOf("/") + 4
'4 for the year xx/xx/2001
sbuilder.Append(pRow(4).ToString.Chars(intI))
Next
TABLE1.Rows(row).Cells(3).InnerText = sBuilder.ToString
'clear the builder for the next record
sBuilder.Remove(0, intI)
intI = 0
TABLE1.Rows(row).Cells(1).InnerHtml = "<A HREF='/Searchfiles/" & _
Row(2).ToString & "'>" & pRow(2).ToString & "</A>"
row += 1
'we need this test because we don't want to advance
'the cursor when paging backwards
cursor += 1
If Not rowIterator.MoveNext() Then
Exit While
End If
End While

Regular Expressions

The .NET Framework equips you with probably the most sophisticated and advanced regular expression
engine in existence today. If you don't know what regular expressions are, then consider the definition
provided by this book:

"A regular expression is a character or a combination of characters (which form a pattern)


used to find a matching character, String, or combination of characters in a sample. The
expression can be a simple wildcard, such as the "?" (question mark) or "*" (star or

515

You might also like