Replacement for StrReverse Function

  • Thread starter Thread starter John Cobb
  • Start date Start date
J

John Cobb

I've removed the Microsoft.VisualBasic import from my VB.Net project and am
in the process of replacing the vb6 compatible calls with native .Net i.e.
system.datetime.now instead of Now, variable Is Nothing instead of
IsNothing(variable) etc. I cannot find a native .Net replacement for the
StrReverse function. Is anyone familiar with a quick fix?
 
I've removed the Microsoft.VisualBasic import from my VB.Net project and am
in the process of replacing the vb6 compatible calls with native .Net i.e.
system.datetime.now instead of Now, variable Is Nothing instead of
IsNothing(variable) etc. I cannot find a native .Net replacement for the
StrReverse function. Is anyone familiar with a quick fix?

How 'bout something like this :)

Private Function ReverseString(ByVal input As String) As String
If Not IsNothing(input) Then
Dim chars() As Char = input.ToCharArray()
Array.Reverse(chars)
Return New String(chars)
End If
End Function
 
Hi Cor,
At the Develop Mentor Architect Training event hosted by Microsoft in the
Dallas office this week the instructor was showing how some functions like
these are wrapped by .Net to allow backwards compatibility. If you use
ildasm to look at the intermediate language of your assembly you can see
where things like OnError Goto etc. generate more IL than if you use the
native .Net functionality. It was suggested there to remove the
Microsoft.VisualBasic import and replace functions like Asc, Left$,
StrReverse, etc. with true .Net commands to generate leaner, tighter code.
 
Tom,
Yes, that will work and I'll probably use something like that if there's not
a native .Net function already available. I was just curious if this
functionality was already part of the framework.
 
Hi Tom,


Especialy that IsNothing(input) that is real the one.

:-))

Cor

Actually, I think I would change the test to:

If Not IsNothing(input) AndAlso input.Length <> 0 Then
...
End If
 
* "John Cobb said:
I've removed the Microsoft.VisualBasic import from my VB.Net project and am

Are you ill?
in the process of replacing the vb6 compatible calls with native .Net i.e.

'Microsoft.VisualBasic' (in "Microsoft.VisualBasic.dll") doesn't include
"VB6 compatible calls", it simply includes VB.NET methods. The
compatibility functions are in the
'Microsoft.VisualBasic.Compatibility.VB6' namespace (in
"Microsoft.VisualBasic.Compatibility.dll").
system.datetime.now instead of Now, variable Is Nothing instead of
IsNothing(variable) etc.

'IsNothing' is not the same as 'Is Nothing'!
I cannot find a native .Net replacement for the
StrReverse function. Is anyone familiar with a quick fix?

I don't think that there is one. I would continue using VB.NET's
'StrReverse' function.
 
Tom,
Yes, that will work and I'll probably use something like that if there's not
a native .Net function already available. I was just curious if this
functionality was already part of the framework.

Other the the VB.NET StrReverse function - then I'm not aware of it.
Unless it's lurking in System.Text.RegularExpressions - and I generally
avoid that namespace since the implementation is so slow...
 
* Tom Shelton said:
How 'bout something like this :)

Private Function ReverseString(ByVal input As String) As String
If Not IsNothing(input) Then

LOL ;-)!
 
* "John Cobb said:
Yes, that will work and I'll probably use something like that if there's not
a native .Net function already available. I was just curious if this
functionality was already part of the framework.

The Visual Basic .NET runtime actually /is/ part of the framework.
 
Hi John,

Did you see OnError and Goto on the link I did send?

Are you sure it was not about the compatible namespace?

Cor
 
Herfried K. Wagner said:
am

Are you ill?
LOL. Not that I know of.
At the Develop Mentor Architect Training event hosted by Microsoft in
the Dallas office this week the instructor was showing how some functions
like
these are wrapped by .Net to allow backwards compatibility with vb6 and if
you use
ildasm to look at the intermediate language of your assembly you can see
where certain ones generate more IL than native .Net commands. It was
suggested there to remove the Microsoft.VisualBasic import and use true .Net
commands to generate leaner, tighter code. As a best practice, my team
leader has dictated we elminate the Microsoft.VisualBasic import from all of
our code.
 
'IsNothing' is part of 'Microsoft.VisualBasic' and the OP doesn't want
to use this namespace ;-).

Oh, yeah! Ok, then change it to:

If Not input Is Nothing ....

Sorry.
 
John,

* "John Cobb said:
LOL. Not that I know of.
;-)

At the Develop Mentor Architect Training event hosted by Microsoft in
the Dallas office this week the instructor was showing how some functions
like
these are wrapped by .Net to allow backwards compatibility with vb6 and if
you use

Partly I agree. Some of the methods in the Visual Basic .NET Runtime
Library internally base on methods of the .NET Framework, but most of
them are more than a "wrapper". For example, 'IsNumeric' is performing
much more operations than you may expect it to do.
ildasm to look at the intermediate language of your assembly you can see
where certain ones generate more IL than native .Net commands. It was
suggested there to remove the Microsoft.VisualBasic import and use true .Net

I would not do that.
commands to generate leaner, tighter code.

Tell me, what's "cleaner" than 'Strings.StrReverse'? I don't see
anything dirty there.
As a best practice, my team
leader has dictated we elminate the Microsoft.VisualBasic import
from all of our code.

Tell him that this is nonsense ;-).
 
Hi,

There are lots of silly suggestions around. That sounds like one of them to
me. IMO, of course.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Hi Herfried,

As far as I know are the connection classes also a wrappers, I do not
believe that it is wise to delete those classes as well from the library

(That is in my opinion the main reason why there is always that discussion
about dispose with that one).

Just my thought,

Cor
 
Back
Top