Question

  • Creator
    Topic
  • #4011753

    “Split” error when running code for application

    by HarryStoun ·

    I wrote a code in Kotlin and when I run it I get an error Unresolved reference: split. I do not understand something how to fix this, because so far there is little practice with this programming language.

    fun main() {
    val str = “A:B:C”
    val delim = “:”

    val list = str.split(delim)

    println(list) // [A, B, C]
    }

    • This topic was modified 1 year, 4 months ago by Avatar photokees_b.

You are posting a reply to: “Split” error when running code for application

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

  • Author
    Replies
    • #4011760
      Avatar photo

      Reply To: “Split” error when running code for application

      by kees_b ·

      In reply to “Split” error when running code for application

      Apparently, it doesn’t know the method split for the variable str. Better study the documentation of the language.

      • This reply was modified 1 year, 4 months ago by Avatar photokees_b.
      • This reply was modified 1 year, 4 months ago by Avatar photokees_b.
    • #4100364
      Avatar photo

      Reply To: “Split” error when running code for application

      by Rohit Sri ·

      In reply to “Split” error when running code for application

      The code you provided seems correct, and the error you’re encountering is likely due to a typographical issue. In Kotlin, strings are enclosed in double quotes (“), but in your code, you used typographic quotes (“”).

      To fix the error, replace the typographic quotes around the str variable and the delim variable with regular double quotes. Here’s the corrected code

      fun main() {
      val str = “A:B:C”
      val delim = “:”

      val list = str.split(delim)

      println(list) // [A, B, C]
      }

      After making this change, the split function should work as expected, splitting the string str at each occurrence of the delimiter delim.

Viewing 1 reply thread