I am forever using classes that are missing a method or two that I then have to separately implement and use differently to those provided by the class.
So I'm thinking, what about a class module named [type/class]+[description] eg String+LeftRightAndMaybeMore to add extra methods to type/class String, like:
which you could then use just like all the other regular String methods eg:
without trying to remember heck, is that a built-in function or do I have to dim and prefix it with a dummy object of StringUtils or ByteConverter or StringFunctions ???
Anyway, back to that poker game Optical Card Recognition challenge... ?
So I'm thinking, what about a class module named [type/class]+[description] eg String+LeftRightAndMaybeMore to add extra methods to type/class String, like:
String+LeftRightAndMaybeMore:
Public Sub Left(N As Int) As String
If N <= 0 Then
Return ""
Else
Dim S As String = Me 'or whatever it takes to get a hold on the String object that this method is being applied to
If N >= S.Length Then
Return S
Else
Return S.SubString2(S, 0, N)
End If
End If
End Sub
Public Sub Right(N As Int) As String
If N <= 0 Then
Return ""
Else
Dim S As String = Me
If N >= S.Length Then
Return S
Else
Return S.SubString(S.Length - N)
End If
End If
End Sub
Public Sub ToCharArray As Char()
Dim S As String = Me
Dim bc as ByteConverter
return bc.ToChars(S)
End Sub
Public Sub ToProperCase As String
Dim S As String = Me
Dim C() As Char = S.ToLowerCase.ToCharArray
Dim UpperNext As Boolean = True
For I = 0 to C.Length - 1
If C(I).IsLetter Then
If UpperNext Then
C(I) = C(I).ToUpperCase
End If
UpperNext = False
Else
UpperNext = True
End If
Next
Return C.ToString 'per class file CharArray+ToStringAndMore
End Sub
which you could then use just like all the other regular String methods eg:
MyBoringCode:
Log("noW iS thE timE foR alL gooD meN tO comE tO thE aID oF thE partY".Left(15).ToProperCase) 'Now Is The Time
without trying to remember heck, is that a built-in function or do I have to dim and prefix it with a dummy object of StringUtils or ByteConverter or StringFunctions ???
Anyway, back to that poker game Optical Card Recognition challenge... ?
Last edited: