tags:

views:

59

answers:

2

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:

:[email protected] 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.

A: 

You can use RegEx to get everything between the first : and !

(?<=:).*?(?=!)

and then look for everything between the last #channel : and the end of the line

(?<=#channel :).*?(?=$)

This is simple but should take into account that someone may use a semi-colon (:) in the message.

Dave White
A: 

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)))
DaMartyr