6

Consider:

object HelloWorld {
  def main(args: Array[String]): Unit = {

    val s:String = "AbcD"

    println(s.contains("ABCD"))
    println(s.contains("AbcD"))

  }
}

Output:

false
true

I need the result to be true in both cases regardless of the case. Is it possible?

Nilesh
  • 2,054
  • 3
  • 23
  • 43

2 Answers2

25

If you really need contains use

s.toLowerCase.contains("abcd")

But most likely you are looking for

s.equalsIgnoreCase("abcd")
raphaëλ
  • 6,393
  • 2
  • 29
  • 35
  • 5
    just pointing out that if the argument to `contains` is dynamic, they would need to call `toLowerCase` on that as well to be case insensitive all around. – jcern Jul 08 '16 at 13:25
2

with Regex

println(s.matches("(?i:.*" + "ABCD" + ".*)"))
Saqib Ali
  • 3,953
  • 10
  • 55
  • 100