Page 1 of 1
for strings
Posted: Mon Apr 05, 2004 3:21 am
by Dare2
Two wishes:
A default length for Mid - Mid(myString,myPos[,RestOfStringIfNotSpecified])
FindString to have same Mode option as ReplaceString (ignore case) which I assume would be faster than using UCase() functions to force the issue.

Posted: Wed Apr 07, 2004 9:18 pm
by DoubleDutch
Code: Select all
A default length for Mid - Mid(myString,myPos[,RestOfStringIfNotSpecified])
Is this not the same as:

Posted: Wed Apr 07, 2004 9:39 pm
by freak
No. The right command counts 'mypos' chars from the right, whereas a Mid command
with default length would count 'mypos' from the left, and then return the rest of the string.
Example:
Mid("ABCDEFG", 2) would be "BCDEFG" (starting from 2nd char till the end)
Right("ABCDEFG", 2) would be "FG" (the 2 characters at the right side of the string)
This is really a good idea, and lots of languages have that.
It saves some typing.
Timo
Posted: Thu Apr 08, 2004 12:16 am
by DoubleDutch
Sorry, must have been a bit crazy for that last post! Been shopping with the girlfriend - it does that to ya!
Anyhow, this seems to work...
Code: Select all
a$="qwertyuiop"
b$=mid(a$,3,$7fff)
this will return "ertyuiop"
I just tried it with $7fff, a bigger number will work - prob make it a constant. $7fff seems to be overkill though.
The "MID" command appears to clip on the length of the original string.
Is this what your looking for?
Posted: Thu Apr 08, 2004 1:44 am
by Dare2
Hi DoubleDutch,
Caution: Shopping with the ladies is hazardous to your bank balance!
Thanks for the response.
I was aware of the fact you could overstate the length, but I get nervous in case something changes into the future and a recompile ceases to work. Or (hope against hope) binary strings and fixed length strings get supported!
Anyhow I use a little sum:
mid(str.s, pos.l, len(str) - pos.l + 1)
when mid-ding.
As freak said, just looking to save some typing (and typos).

More Discussion
Posted: Fri Apr 16, 2004 5:13 am
by oldefoxx
Mid() not only allows you to access portion of a string, with suitable arguements it can replace the Left() and Right() functions as well.
I realize it may be poor taste to compare features with another product,
so rather than mention names, let me just say that there is a Mid() statement as well as a Mid() function in some languages. When used on the left side of an assign statement (separated by "="), you can replace a portion of an existing string with a different substring. Since this happens within the existing string (limited by the size of the original string), it can perform very fast, because it does not have to reallocate string memory.
You could, of course, write your own version using ASM or using string pointers in PB.