Results 1 to 3 of 3

Thread: [RESOLVED] How to make a function like Trim?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Resolved [RESOLVED] How to make a function like Trim?

    So, you know how you can call the Trim function like this

    TrimmedString = SomeString.Trim

    Is there a way for me to make a string manipulation function in that format? A Period instead of Parenthesis?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to make a function like Trim?

    yes. you can add an extensions module + write extension methods for members of the string class
    have a look at the extension methods in my signature

    edit:

    here's a more specific example:

    vb Code:
    1. Module extensions
    2.  
    3.     <System.Runtime.CompilerServices.Extension()> _
    4.     Public Function addDollarSign(ByVal instance As String) As String
    5.         Return instance & "$"
    6.     End Function
    7.  
    8. End Module

    to use it:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         MsgBox("money".addDollarSign)
    5.     End Sub
    6.  
    7. End Class

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Re: How to make a function like Trim?

    Thank you, works perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width