VB Mid() funtion in C#

  • Thread starter Thread starter Tom J \(Darth\)
  • Start date Start date
T

Tom J \(Darth\)

Is there by chance a function in C# that can be used just like the built-in
Mid(str,z,z) in VB?
 
There are equivalent method in C# string class. Couldn't remember
exactly what is the method name, but it is there.
 
William Ryan said:
I think Microsoft.VisualBasic.Interaction.Mid( , ); should work.

That reduces portability to other implementations, however, and doesn't
exactly produce idiomatic C# - using String.Substring is far
preferable, IMO.
 
Thanks to all for your input. I am finding that the following statement:
if Mid(Record.GetString(2),1,1) != "9"

Causes a red underscore to appear under Mid and after the quoted string
variable (in this case "9") when I enter this statement under VS .NET Studio
2003. I believe the (String.Substring function) is a better option at this
point. My resolved statement looks something like this:

if (Record.GetString(2).Substring(0,1) != "9")

I'll keep you guys posted as to the outcome of this trial when I try to
Build and run my project.

Thanks again....Tom J
 
I am curious, why do you say that?

This is a few reasons I can think of. If you used the vb functions the world won't grid to a halt but I think it is better not to
use them.

Easier to transfer code to other languages.
Consistancy with other programmers.
There would be a small speed difference because the VB library would need to be loaded.
 
Tom,

The Substring method of the String object should do the trick. It's not a
static method, so call it against the string object you want to parse.

HTH,
Nicole
 
Back
Top