Other than the syntactic difference of being a method instead of a
function, this method behaves identically to the LEFT( ) function.
To use the left() method you need to do this:
c=new string('raymond')
? c.left(2) would give you ra
on the other hand if you're dealing with a string that you haven't made an
object (memeber of the string class) you might say
c='raymond'
? left(c,2) would give you ra
the difference is when you create a string object it encapuslates the value
of the string and you can then use dot notation to access it's methods
(which are similar to string functions). In some cases it makes a
difference, you might be able to do things with the method that you can't
as easily do with the string functions. I usually use the functions tho in
a recent application i played around with the methods and they were easy to
use and easier logic to follow in my code.
Another thing with SOME string methods is that they are zero based instead
of one based. For instance
c='raymond'
substr(c,1,1)='r'
however
c=new string('raymond')
c.substring(1,1)='a' because the string starts at zero c.substring(0,1)='r'
Hope this helps a little, perhaps someone who knows alot more about this
than I can explain more if you need it.
As Howard points out, they are quite similar. The lower case version
references a method of a class; the upper case version references a
language FUNCTION.
One thing that I don't think Howard may even realize, is that you can
bypass creating an instance of the string object, and just use the
methods directly on a string:
? "Raymond".left(2)
// will return "Ra"
cName = "Raymond"
? cName.left(2)
// will also return "Ra"
Etc.
The string class methods work on literal strings, and pretty much
anywhere a string exists. Another example:
form.rowset.fields["First Name"].value.left(2)
Will also work (I use this periodically for some of my own code <G>).
Ken
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **
"Think OOP"
dBASE, Inc. website: http://www.dbase.com
>