First off, you should parse the IRC message properly. It’ll save quite a bit of trouble doing it right the first time around.
The second thing is, you only need to identify it as a PING, the trailing part (tmi.twitch.tv) is irrelevant, you’ll just stick it in your PONG reply.
Here’s a snippet from TwitchChatSharp (C#)
var ircMsg = IrcMessage.FromRawMessage(message);
MessageReceived(this, new IrcMessageEventArgs(ircMsg));
switch (ircMsg.Command)
{
case IrcCommand.Ping:
EnqueueMessage(message.Replace("PING", "PONG"), true);
break;
case IrcCommand.Reconnect:
Disconnect();
break;
}
As a side-note, please surround code with triple backticks and it’ll show up properly:
```
// code here
```