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?

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.