Search code examples
vb.netregexirc

How can I get the nickname and message from raw IRC data in vb.net


Well basically I've got a vb.net script connecting to IRC, and I'm working on making it a basic chat system, but I've run into a problem.

Say I receive this:

:nickname!name@tw-32151D9B.hsd1.vt.comcast.net PRIVMSG #channel :message

I want to grab specific information to output to the user.

I want to grab nickname and message

How can I go about doing this?

I thought about using regex, but I can't figure out how to make regex grab message since there's nothing after it.


Solution

  • I love IRC. The following code will do what you want assuming your raw data is in the variable strData.

    Dim strNickName As String = String.Empty
    Dim strMessage As String = String.Empty
    
    Dim intToMessage As Integer = 0
    Dim intParse As Integer = 0
    
    intParse = InStr(strData, "!")
    strNickName = Mid(strData, 2, (intStart - 2))
    
    intToMessage = InStr(strData, "PRIVMSG #")
    intParse = InStr(Mid(strData, intToMessage, (Len(strData) - intToMessage)), ":")
    strMessage = Mid(strData, (intToMessage + intStart), (Len(strData) - (intToMessage + intStart - 1)))