Operator overloading in Kotlin

Viewed 613

String division using operator overloading in Kotlin, please help me to complete this code. No change can be made in main function. Find common from both string like a=aabcc b=abdec answer=abc (unique common characters)

fun main(args: Array<String>) 
{
      val a:String = readLine()!!

      val b:String = readLine()!!

      val result = a/b

      println(result)
 }
1 Answers

Operators can be defined externaly, just like extension functions:

operator fun String.div(other: String): String {
    // Put your implementation here
}

As for the implementation: you should probably do your assignment yourself.

Related