int nFirstSpace = FindSubString(sChat, " ", 0);
int nSecondSpace = FindSubString(sChat, " ", nFirstSpace + 1);
int nThirdSpace = FindSubString(sChat, " ", nSecondSpace + 1);
string sCommand = (GetSubString(sChat, 0, 1) == "!" ? GetSubString(sChat, 1, nFirstSpace - 1) : sChat);
string sParam1 = GetSubString(sChat, nFirstSpace + 1, (nSecondSpace != -1 ? nSecondSpace: GetStringLength(sChat) - (nFirstSpace + 1)) - 1);
string sParam2 = GetSubString(sChat, nSecondSpace + 1, (nThirdSpace != -1 ? nThirdSpace: GetStringLength(sChat) - (nSecondSpace + 1)) - 1);
If I enter the string "!test apple"
sCommand = 'test' and
sParam1 = 'apple'
sParam2 = '!test' (redundant anyway, don't care)
If I enter the string "!test apple pear"
sCommand = 'test'
sParam1 = 'apple pear'
sParam2 = 'pear'
Anyone help me with a correct (and no doubt more efficient) way of parsing strings with spaces/
Modifié par Werehound, 13 avril 2011 - 01:43 .