Using the Visual Studio Find/Replace (with the regex options enabled) you can use this:
Find what: If {:a+}\.Length \> 0
Replace with: If Len(\1) \> 0
Pattern explanation:
:a+
= the :a
matches an alphanumeric char, and the +
matches at least one occurrence
{}
in {:a+}
= Visual Studio regex's way of "tagging" (i.e., capturing) an expression
\>
= the >
must be escaped with a backslash since it's a metacharacter in this regex flavor.
\1
= refers to the text matched in the tagged expression. The number 1
refers to the first (and only, in this case) tagged expression.
You can read more about the MSDN regex reference for Find/Replace here.
As I had mentioned in my comment, I think using Len()
is a step backwards and ties your code down to the Microsoft.VisualBasic
namespace. @drventure brought up a good point though, since calling .Length
on a null value would throw an exception. Instead of checking the length you could use String.IsNullOrEmpty. In .NET 4.0 you can also use String.IsNullOrWhiteSpace.
Instead of If strErrorMessage.Length > 0
you can use:
If Not String.IsNullOrEmpty(strErrorMessage) Then
' or '
If Not String.IsNullOrWhiteSpace(strErrorMessage) Then
If you're interested in using this you can keep the original "Find what" pattern and change the "Replace with" pattern to this: If Not String.IsNullOrEmpty(\1)