Menu
Бг | Es
Asp.net blog


Remove HTML from string with regular expression

It's really simple to do that with just a few lines of code. Here is how to:

Private Function RemoveHTML(ByVal str As String) As String
Dim RegExp As String = "<[^>]*>"
Dim R As New Regex(RegExp)
Return R.Replace(str, " ")
End Function


And you can get the "clear" string for your label control (for example):

Label1.Text = RemoveHTML(TextBox1.Text)



Getting web file content from url with ASP.NET 3.5

Here's how you could get page or file content with help of webclient class and use it for example to get the forex rates or regional weather forecast from diferent page and show it to yours:

First we need to import the required name spaces:

Imports System.Net
Imports System.IO

Second there we go with our method:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim client As New WebClient

Dim sr As StreamReader = New StreamReader(client.OpenRead("http://www.snb-bg.com/test.txt"), System.Text.Encoding.Default(), False)
Dim sb As New StringBuilder

Do While sr.Peek >= 0
sb.Append(sr.ReadLine())
Loop

Label1.Text = sb.ToString()
client.Dispose()
sr.Dispose()
sr.Close()
End Sub

I think this example is quite easy and don't need more explanation, but in case you need please feel free to send me feedback.




Get Windows Serial Number with VB.NET

I'll show you fast and easy way to get operating system serial number that the application is running on. Here how to accomplish this task:

In Page_Load event handler (for example) getting WSN:

Dim MOS As ManagementObjectSearcher = New ManagementObjectSearcher("Select * From Win32_OperatingSystem")
Dim MO As System.Management.ManagementObject
Dim MOC As System.Management.ManagementObjectCollection = MOS.Get
Dim WindowsSerial As String = String.Empty

For Each MO In MOC
   WindowsSerial = MO("SerialNumber")
Next
1 2 3 
Copyright © 2009 SNB Solutions