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.
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)))
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.
精彩评论