String Class
| From: | Matthew Fonda | Date: | Mon, 13 Dec 2004 01:43:09 +0000 |
| Subject: | String Class | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-35023@lists.php.net to get a copy of this message | ||
Hello,
I have created a string class in PHP. It is pretty much a copy of java's
String class, but it will add a few new features, and allows you to do
certain things with strings in PHP easier and quicker. I find this
useful when you are using strings that you need to do a lot of stuff to,
it works better than just using PHP's default string functions, and
provides an OOP wrapper for them. I plan to add more features to it as
well, but here is a little example:
require_once 'string.php'
$s = new String(' this is a test string ')
------------------------
$s->charAt(3): i
$s->compareTo(' THIS IS A TEST STRING '):
$s->compareToIgnoreCase(' THIS IS A TEST STRING '): 1
$s->concat('value');
$s: this is a test string value
$s->endsWith('lue'): 1
$s->equals(' THIS IS A TEST STRING value'):
$s->$s->equalsIgnoreCase(' THIS IS A TEST STRING value'): 1
$s->getChars() example:
------
$chars = array();
$s->getChars(16, 22, $chars, 0);
print_r($chars):
Array
(
[0] => s
[1] => t
[2] => r
[3] => i
[4] => n
[5] => g
)
$s->hashCode(): -1891164387
$s->indexOf('s'): 4
$s->indexOf('s', 5): 7
$s->lastIndexOf('s'): 16
$s->length(): 28
$s->replace('t', 'T'): This is a TesT sTring value
$s->startsWith(' this'): 1
$s->substring(1): this is a test string value
$s->substring(1,5): this
print_r($s->toCharArray());
Array
(
[0] =>
[1] => t
[2] => h
[3] => i
[4] => s
[5] =>
[6] => i
[7] => s
[8] =>
[9] => a
[10] =>
[11] => t
[12] => e
[13] => s
[14] => t
[15] =>
[16] => s
[17] => t
[18] => r
[19] => i
[20] => n
[21] => g
[22] =>
[23] => v
[24] => a
[25] => l
[26] => u
[27] => e
)
$s->toLowerCase(): this is a test string value
$s->toUpperCase(): THIS IS A TEST STRING VALUE
$s->trim(): this is a test string value
I think this can be useful and make things a lot easier in some cases.
Any ideas or thoughts on this, or things to improve, or things to be
added, etc.
Thanks
--
Regards,
Matthew Fonda