for strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

for strings

Post 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.

:)
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Code: Select all

A default length for Mid - Mid(myString,myPos[,RestOfStringIfNotSpecified]) 
Is this not the same as:

Code: Select all

Right(mystring,mypos)
:?:
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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). :)
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

More Discussion

Post 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.
has-been wanna-be (You may not agree with what I say, but it will make you think).
Post Reply