Creating an AIM Plugin in VB.NET Using the .NET Framework - Part 2
Welcome back.
The method m_session_BeforeImSend calls the transmogrify function. Since there isn't one there, we'll add it. The transmogrify function takes a string and shifts each letter 13 characters then returns the "transmogrified" string:
''' <summary>
''' All letters in a sent IM will be shifted 13 places.
''' </summary>
''' <param name="s"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function transmogrify(ByVal s As String) As String
Dim output As New StringBuilder
Dim chs As Char() = s.ToCharArray
For i As Integer = 0 To s.Length - 1
Select Case chs(1)
Case "a"c
output.Append("n")
Case Else
output.Append(chs(i).ToString)
End Select
Next i
Return output.ToString
End Function
I have no idea why the author uses a StringBuilder instead of a regular String. Maybe you can try it and tell me what the difference is. Just like the original author, I'm not going to implement all 52 cases either. I will say that there is definitely an easier way than actually defining 52 cases.
Think about it like this. If the letter is the 14th letter (N) of the alphabet (26 letters total), then shifting it 13 places would be (A). All characters have numeric values. For anything less than N, add 13. For anything N or later, start with the value 12 less than A's value, and then add 13. Two cases will handle the entire alphabet.
Or, for the sake of testing, you could have this function return something like "I love ______!" no matter what is typed. I have "Julia" in that blank.
If you didn't know (it was news to me when I found out), you can specify the text for your custom functions and parameters that Intellisense displays. Just type:
'''
before any class, subroutine, function, property, or structure declaration, and you will be able to describe in more detail what this piece of code does. Excellent if you have to share code.
Additionally, what I just learned today, a single quoted letter or character followed by c will give you the Char value. Priceless.
This is the end of Part 2 of this post. Come back for part 3.
The method m_session_BeforeImSend calls the transmogrify function. Since there isn't one there, we'll add it. The transmogrify function takes a string and shifts each letter 13 characters then returns the "transmogrified" string:
''' <summary>
''' All letters in a sent IM will be shifted 13 places.
''' </summary>
''' <param name="s"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function transmogrify(ByVal s As String) As String
Dim output As New StringBuilder
Dim chs As Char() = s.ToCharArray
For i As Integer = 0 To s.Length - 1
Select Case chs(1)
Case "a"c
output.Append("n")
Case Else
output.Append(chs(i).ToString)
End Select
Next i
Return output.ToString
End Function
I have no idea why the author uses a StringBuilder instead of a regular String. Maybe you can try it and tell me what the difference is. Just like the original author, I'm not going to implement all 52 cases either. I will say that there is definitely an easier way than actually defining 52 cases.
Think about it like this. If the letter is the 14th letter (N) of the alphabet (26 letters total), then shifting it 13 places would be (A). All characters have numeric values. For anything less than N, add 13. For anything N or later, start with the value 12 less than A's value, and then add 13. Two cases will handle the entire alphabet.
Or, for the sake of testing, you could have this function return something like "I love ______!" no matter what is typed. I have "Julia" in that blank.
If you didn't know (it was news to me when I found out), you can specify the text for your custom functions and parameters that Intellisense displays. Just type:
'''
before any class, subroutine, function, property, or structure declaration, and you will be able to describe in more detail what this piece of code does. Excellent if you have to share code.
Additionally, what I just learned today, a single quoted letter or character followed by c will give you the Char value. Priceless.
This is the end of Part 2 of this post. Come back for part 3.
Labels: aim, programming, vb.net, visual studio

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home