TGC Codebase Backup



Better, Faster, Old by shortwind

14th Jan 2006 21:39
Summary

Better, Faster old style MID$ function.



Description

This is a newMid$ function. This is better and faster than previous code posted on this site. This recreates the old-style MID$(<string>,start_position,length) code more closely. The code is also faster.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    print "This is a faster function to simulate a real MID$ function."
print "This routine has basic overflow protection.  If the start+length"
print "is longer than the string, it will return the start correctly, and"
print "then the rest of the string.  This is a function of some versions of the"
print "MID$ function in other basics."
print " "
print "newMid$(<string>,start,length)"

a$="abcdefghijklmnopqrstuvwxyz"
b=3
c=4

print "string$=";a$
print "start=";b
print "length=";c

print "The result = ";newMid$(a$,b,c)

print " ": print "press any key to continue"
wait key

function newMid$(a$,b,c)
   if len(a$)<c then c=len(a$)-b+1
   ReturnValue$=right$(left$(a$,b+c-1),c)

endfunction ReturnValue$