[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
VBHowTo_MidStatement
Did you know you can use Mid$ not only as a function but also as a Statement? Visual Basic 6 has a special implementation for Mid$ so it can be used as a statement to paste a string within an already existing string, without having to reallocate memory, making it much faster than string addition using string1 & string2
sText = "Did you know about Mid$?"
Mid$(sText, 19, 4) = "this"
- sText -
"Did you know about this?"


You can also ommit the length if you wish:
sText = "Did you know about Mid$?"
Mid$(sText, 19) = "this"
- sText -
"Did you know about this?"


When the string you are trying to insert is larger than the length of the string it is cut off:
sText = "Did you know about Mid$?"
Mid$(sText, 14, 22) = "it cuts off the string?"
- sText -
"Did you know it cuts off"
Here too, the Length can be omitted.

Using the Mid$ statement can be much faster when working with large strings and can be used to highly optimize code.

A good article about how to use this to optimize 'string concatenation' is found on MSDN Library

last edited (January 14, 2007) by BitByBit_Thor, Number of views: 675, Current Rev: 1

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.