2

I have a string like this bla bla. In my class I have code like this:

String str = 'bla bla';
system.debug(str.containsNone(', '));  //debug result FALSE
system.debug(str.containsNone(','));   //debug result TRUE

First debug outputs false and second one outputs true while documentation says:

containsNone(substring): Returns true if the current String doesn’t contain the specified sequence of characters; otherwise, returns false.

According to this output must be false for both.

Am I missing something here?

1 Answer 1

3

Perhaps the phrasing is poor, but containsNone is not simply !contains, which is how you are interpreting it. A more correct description might be:

containsNone(substring): Returns true if the current String doesn’t contain any of the specified characters; otherwise, returns false.

Because your string contains the space character, it returns false.

4
  • 2
    I nominate @AdrianLarson to create the Apex doc feedback to SFDC :-)
    – cropredy
    Commented Jan 22, 2016 at 20:56
  • @crop1645 I hope Adrian does. I just met our docs team and they take feedback very seriously Commented Jan 23, 2016 at 6:21
  • So it is the opposite of containsAny(substring) :)
    – abdn
    Commented Jan 23, 2016 at 13:26
  • @abdn Yep. Sure makes a lot more sense that way!
    – Adrian Larson
    Commented Jan 23, 2016 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .