/* = instr ("-=CW=-KaReL*recon*", "CW"); OK, "little" explanation: first i loop through the whole string, beginning from 1st char to the last from the 1st string. if i find a char in string 1 that is equal to the first char in string 2, i go into the second for-loop there i'm looping through string 2, taking string 1 with me. So i know the first char (str2) equals the xth char of str1. We take a look then to the 2nd char of str2, comparing it with xth+1 char of str1. If this one's right => next char; else break outta 2nd for-loop & tell them the found character was NOT right Then if the whole substring was found (2nd for-loop was ended w/o going into the if-statement (so WeGotOne stays true (1)) we return 1 Otherwise, clean up the vars... [WeGotOne = TRUE (again) & j inited at 0!! BE CAREFULL!! this j=0 isn't redundant! This because strings start with 0, not 1! */ /* Credits: -=CW=-KaReL*recon* */ instr(StrOne[], SearchStr[]) { new strLen1 = strlen(StrOne); new strLen2 = strlen(SearchStr); new Text[MAX_TEXT_LENGTH]; if (strLen1 == 0 || strLen2 == 0) { return -1; // 0 length string ... nothing to compare -> return -1; } else if (strLen1 < strLen2) { // so if we forget the right syntax & entered sth like instr("-=CW=-", "-=CW=-KaReL*recon*"); return instr(SearchStr, StrOne); } else if (strLen1 == strLen2) { if (streq(StrOne, SearchStr) == 1) { // -1 if not found, 0 if found (place where SearchStr resides actually :-) ) strncpy(Text, "^"", MAX_TEXT_LENGTH); strcat (Text, StrOne); strcat (Text, "^" seems to be equal to ^""); strcat (Text, SearchStr); strcat (Text, "^"."); DebugMessage(Text); return 0; } else { strncpy(Text, "^"", MAX_TEXT_LENGTH); strcat (Text, StrOne); strcat (Text, "^" seems NOT to be equal to ^""); strcat (Text, SearchStr); strcat (Text, "^"."); DebugMessage(Text); return -1; } } else { // declare them when we need them ... new i = 0; new j = 0; new WeGotOne = 1; // we got 1 (default) if (strLen2 == 1) { // we only have to find if the specified char is in our string ... for ( i = 0; i < strLen1; i++ ) { if (tolower(StrOne[i]) == tolower(SearchStr[0])) { return i; // FOUND IT!!! at place i+1, this is in strings charAt place i+1 } } } else { for ( i=0; i < strLen1; i++ ) { if ( tolower(StrOne[i]) == tolower(SearchStr[j]) ) { /* char found ... */ for( j = 1; j < strLen2; j++ ) { i++; // no good programmin', but who cares ;p? if ( tolower(StrOne[i]) != tolower(SearchStr[j]) ) { WeGotOne = 0; // Nah, not right ... // j = strLen2; /* REMOVED */ break; /* UPDATED -> nicer way of programming ;-) We should now 'break' outta second for-loop */ } } if ( WeGotOne ) { return i - strLen2 + 1; } else { WeGotOne = 1; j=0; i--; // else if i gave myself a name like -=CCW=-KaReL*recon* & i checked for CW (what is actually // in it), i was receiving a -1!! } } /* char not found */ } } } return -1; }