# Bug in String::indexOfAnyOf

**URL:** <https://forum.juce.com/t/bug-in-string-indexofanyof/2797>\
**Category:** General JUCE discussion\
**Created:** [May 3, 2008, 3:03pm UTC](https://forum.juce.com/t/bug-in-string-indexofanyof/2797 "2008-05-03T15:03:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![francis](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@francis](https://forum.juce.com/u/francis)\
**Post date:** [May 3, 2008, 3:03pm UTC](https://forum.juce.com/t/bug-in-string-indexofanyof/2797/1 "2008-05-03T15:03:57Z")

</div>

I think this is a bug in String::indexOfAnyOf:

```auto
    while (*t != 0)
        if (CharacterFunctions::indexOfChar (charactersToLookFor, *t++, ignoreCase) >= 0)
            return (int) (t - text->text);
```

When one of the charactersToLookFor is found, t is incremented before returning the result. The function thus returns the character index + 1.

The simple fix:

```auto
    while (*t != 0)
    {
        if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
            return (int) (t - text->text);
        ++t;
    }
```

regards,  
Francis.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 4, 2008, 7:14pm UTC](https://forum.juce.com/t/bug-in-string-indexofanyof/2797/2 "2008-05-04T19:14:52Z")

</div>

wow - you’re quite right, I’m surprised I never came across that one before! Thanks, I’ll get a fix checked in asap.
