[NEVER MIND]: Find First [Not] Of function(s)?

Started by monkey0506, Mon 09/05/2005 13:57:05

Previous topic - Next topic

monkey0506

I don't have access to the manual ATM, but I did search the forums and couldn't find anything related to this, so...Is there a function like C++'s stringname.find_first_not_of() function?  I'm trying to find the first character that isn't one of a specific set of delimeters...Any help would be appreciated.

Pumaman

Nope, you'd need to do it the long way (ie. loop through each character and do an "if (letter == 'A') || (letter == 'B'))" type thing).

monkey0506

Egads!  Although I already started writing the code that way (on paper), I had hoped that there would be something easier...  Could this possibly be implemented (aka changing this thread to a suggestion...)?  I mean, would anyone else find it useful?

Pumaman

Well, the script isn't really that complicated:

int a = 0;
while (a < StrLen(stringname)) {
  int theChar = StrGetCharAt(stringname, a);
  if ((theChar != 'A') && (theChar != 'B') && (theChar != 'C')) {
    Display("The first character that's not one of the delimiters is %c.", theChar);
    break;
  }
  a++;
}

monkey0506

I was thinking it would be harder to handle if you had to run through several characters of several strings with several delimiters, but I'm working on writing some custom functions:

StrFindFirstOf(string text, string delimiters)
StrFindFirstNotOf(string text, string delimiters)
StrFindFirstOfRevers(string text, string delimiters) /* same as StrFindFirstOf only runs from the end of string to the beginning */
StrFindFirstNotOfReverse(string text, string delimiters) /* runs end to beginning of string */

SMF spam blocked by CleanTalk