 |
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003  | This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 7th, 2005, 08:01 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Adding functionality to the String class?
Hi all,
Not sure if anyone can help me..
I have written a Proper Case function which does, well exactly what it says on the tin...what I would like to do now is add it to the String class, appreciating that I can't I was hoping that I could write my own class - lets say RobsStringClass which would inherit the system.string class and then also have my nice new function.
Alas this doesn't seem to be the case as the string class appears to be sealed..
I was hoping that a user of my class would be able to do something like this:
Dim myString As String
myString = "HELLO WORLD"
myString = myString.ToProperCase()
the end result being:
Hello World
Can anyone suggest a way to get all of the functionality from String into another class where I can add my own function too?
Thanks in advance for any help.
Regards
Rob
__________________
Regards
Rob
|
|

February 7th, 2005, 09:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You can create your own class for this, but you can't like inherit from the string class, that I know of. You can create your own custom helper class.
Brian
|
|

February 7th, 2005, 02:44 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Brian,
Thanks for your reply.
Yeah, the not being able to inherit from the String class is a bit of a pain, someone on a news group suggested that the String class was one of the most used, I guess it's probably one of the weighty ones also so perhaps I dont want a class with that included in it, I don't know...
I already have a class for the ProperCase method, but I cant achieve my goal of :
myString = myString.ToProperCase
using it...instead I have to:
myString = ProperCase(myString)
just doesn't look as nice (cosmetically) albeit the result is the same...
Regards
Rob
|
|

February 7th, 2005, 05:44 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You could use myString = myString.ProperCase(), if you declare ProperCase shared/static.
Brian
|
|

February 8th, 2005, 07:53 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Brian,
Thanks for your reply.
Would it be possible for you to give me an example of how to do that? I'm relatively new to .net (had training a year ago but have only been using it for a few months, so slow process etc).
Thanks in advance for any help.
Regards
Rob
Regards
Rob
|
|

February 9th, 2005, 02:11 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Actually, my previous post was wrong (sorry), if you assign the string to the class and not make it static, it may work without the parameter, just have a value private field that stores the underlying string value. If you wanted to do it as a shared function, you need to pass the string, and define it as such:
Public Shared Function ProperCase(text as string) as string
'Transform
end function
Sorry for the mixup.
Brian
|
|
 |