Monday, January 24, 2011

How to identify if string contain a number?

System.Text.RegularExpressions.Regex.IsMatch(input, "\d")

So times you will need to check a string, to see if it contains a number.
What’s the best way to do this?


There are several solutions like this function :

TryParse approach:



Public Shared Function IsNumeric(Expression As Object) As Boolean
    Dim isNum As Boolean
    Dim retNum As Double
    isNum = [Double].TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, retNum)
    Return isNum
End Function

Check Characters in String approach:



Public NotInheritable Class Extensions
    Private Sub New()
    End Sub
    <System.Runtime.CompilerServices.Extension> _
    Public Shared Function IsNumeric(s As String) As Boolean
        For Each c As Char In s
            If Not Char.IsDigit(c) AndAlso c <> "."C Then
                Return False
            End If
        Next
 
        Return True
    End Function
End Class

What about locales where '.' is the group separator, not the comma (e.g. pt-Br)? What about negative numbers?
Group separators (commas in English)? Currency symbols?
TryParse() can manage all of these as required using NumberStyles and IFormatProvider.

Regular Expressions approach:



System.Text.RegularExpressions.Regex.IsMatch(input, "^\d+$")

This will return true if input is all numbers


If you just want to know if it has one or more numbers mixed in with characters, leave off the ^ + and$.



System.Text.RegularExpressions.Regex.IsMatch(input, @"\d")

Actually I think it is better than TryParse because a very long string could potentially overflow TryParse.

Summary


In my opinion the winner is the Regular Expressions Method

Sunday, January 9, 2011

Secunia Personal Software Inspector (PSI)

 

Upon stumbling through the web, I found a nice tool to check the installed software for security issues and out-dated programs.
So I thought I’d shared it with you…

http://secunia.com/vulnerability_scanning/personal/

They even have an online scanning tool, so you don’t need to install the application http://secunia.com/vulnerability_scanning/online/

Screenshot PSI application :image

FREE PC Security for Home Users

The Secunia PSI is a FREE security tool designed to detect vulnerable and out-dated programs and plug-ins which expose your PC to attacks. Attacks exploiting vulnerable programs and plug-ins are rarely blocked by traditional anti-virus and are therefore increasingly "popular" among criminals.
The only solution to block these kind of attacks is to apply security updates, commonly referred to as patches.
Patches are offered free-of-charge by most software vendors, however, finding all these patches is a tedious and time consuming task.
Secunia PSI automates this and alerts you when your programs and plug-ins require updating to stay secure.
Download the Secunia PSI now and secure your PC today - free-of-charge.


Secunia PSI Watch: How to install and use the Secunia PSI 2.0

Current version:
2.0

Latest release:
5th Jan, 2011

File size:
1,737,088 bytes

Alternate download link: ftp://ftp.secunia.com/PSISetup.exe

Older version of the Secunia PSI can be downloaded at:

http://secunia.com/PSI1Setup.exe

System Requirements

The list of requirements that must be met for the Secunia PSI to function correctly are:

Supported Operating Systems (32 & 64 bit):
  • Microsoft Windows 7
  • Microsoft Windows Vista SP 1 or later
  • Microsoft Windows XP - SP 3
Privileges

To install and run the Secunia PSI you require administrative privileges.

Connectivity

Access to Secunia's encrypted servers via SSL (https://psi.secunia.com:443/) and access to Microsoft Windows Update servers,
see also Software Requirements below

Software Requirements

The latest version of Microsoft Update.
You can determine whether or not you are running the latest version by visiting update.microsoft.com.
If you are able to check your system for missing updates through this tool, your system should function properly with the Secunia PSI.

Hardware Requirements:

There are no additional hardware requirements.
If your computer runs any of the above mentioned Operating Systems, then Secunia PSI should work.