Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Contains  RSS feed

 
Bradley Wong
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot find if there is a method that checks if a String contains another String. For example, if there is a code number, say 727anabba, and I want to check if a code number includes abba, how do I do this? is there a function like: boolean codenumber.contains('abba')?? or something like that?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
indexOf() returns a non-negative number if the argument appears in the String it is invoked on, -1 otherwise.
 
Bradley Wong
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool. thx. i will try it out...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For details on indexOf() and other exciting String methods, take a look at the String class documentation. And don't miss out on all of that other useful information found in The API Specification.
[ October 12, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!