Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 7th, 2005, 08:01 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old February 7th, 2005, 09:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
  #3 (permalink)  
Old February 7th, 2005, 02:44 PM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #4 (permalink)  
Old February 7th, 2005, 05:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You could use myString = myString.ProperCase(), if you declare ProperCase shared/static.

Brian
  #5 (permalink)  
Old February 8th, 2005, 07:53 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #6 (permalink)  
Old February 9th, 2005, 02:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
access internal class by adding namespace shubhanker_techgeek General .NET 0 November 24th, 2008 08:49 AM
Adding AJAX functionality to TBH gujju BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 5th, 2008 01:35 AM
adding functionality to a table aceconcepts PHP How-To 0 February 16th, 2006 08:59 AM
adding a class in JavaScript crmpicco Javascript How-To 5 October 4th, 2005 08:15 AM
Adding Page_Load to base class doesn't work Raeldor BOOK: ASP.NET Website Programming Problem-Design-Solution 2 September 24th, 2004 06:30 AM



All times are GMT -4. The time now is 04:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.