strcspn method

int strcspn(
  1. String str1,
  2. String str2
)

Calculates the length of the initial segment of str1 which consists entirely of characters not in str2.

Implementation

int strcspn(String str1, String str2) {
  int count = 0;
  for (int i = 0; i < str1.length; i++) {
    if (!str2.contains(str1[i])) {
      count++;
    } else {
      break;
    }
  }
  return count;
}