String Functions

I am experiencing something very strange in a VB.NET project I am working on. The string functions Left(),Instr(), Right(), etc. do not work, and others, like Replace, do not work correctly. Is this a case of class pollution? If so, how to deal with it?
[253 byte] By [SteveJensen] at [2007-12-24]
# 1

Could you please elaborate? What do you mean that they don't work? Do you get compiler errors? Or is the result not what you expected?

http://msdn2.microsoft.com/en-US/library/microsoft.visualbasic.strings_methods.aspx lists the string methods. Please note that they live in the Microsoft.VisualBasic namespace.

Best regards,
Johan Stenberg

MSJohanStenberg at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Steve,

The System.String class has a wonder and power set methods. You must be an old vb6 programmer and I am too, but I have come to greatly prefer the system.string methods such as string.replace, string.contains, string.substring to the vb functions. For one thing they are zero based which is compatible with vs2005.

It's not that Right and Left no longer work. They are included as Microsoft.VisualBasic.Strings.Right(String, Integer) and all you have to do is to use an Imports statement at the beginning of a class ( Imports Microsoft.VisualBasic.Strings) and that will include the namepsace to make them accessible.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

There must be a conflicting class in my project, because even using imports microsoft.visualbasic in the form does not correct the problem. The Left function appears to get or set an integer related to object coordinates.

By using a the full namespace reference, I can get it to work, but what a pain! LSet does work, though, so I can use it instead.

Thanks for the help!

SteveJensen at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

"The string functions Left(),Instr(), Right(), etc. do not work, and others, like Replace, do not work correctly"

we don;t know exactly what "does not work" mean. Also I've never seen this using purley Microsoft classes.

Let us know more if you can.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
Guessing a bit: Left() and Right() won't work in a Windows Forms form class, their names collide with the Form.Left and Form.Right properties. Use Strings.Left() and Strings.Right() instead. You might have a problem with Replace if you use the String.Replace() method, it takes two arguments, not three as the VB version does and character indexes start from 0, not 1. No idea why the InStr() function would give you trouble, other than that there are two of them, Microsoft.VisualBasic.InStr() and Microsoft.VisualBasic.Strings.InStr().
nobugz at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6
The project has 3rd party references, so it is not purely MS. However, I think you are right, I have to qualify the property references. Thanks.
SteveJensen at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...