Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Kotlin Blueprints

You're reading from   Kotlin Blueprints A practical guide to building industry-grade web, mobile, and desktop applications in Kotlin using frameworks such as Spring Boot and Node.js

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788390804
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Akshay Chordiya Akshay Chordiya
Author Profile Icon Akshay Chordiya
Akshay Chordiya
Ashish Belagali Ashish Belagali
Author Profile Icon Ashish Belagali
Ashish Belagali
Hardik Trivedi Hardik Trivedi
Author Profile Icon Hardik Trivedi
Hardik Trivedi
Arrow right icon
View More author details
Toc

Building our app


We will be building a command-line based CSV reader that prints the unique entries of the columns and their counts, based on user input in Kotlin Native.

Writing the main function

Kotlin Native has the same language syntax and includes the standard library. Hence, the main function in Kotlin Native looks the same as the main function in JVM or JS. It is similar to the following syntax:

    // Starting point
    fun main(args: Array<String>) {
      // Rest of code over here..
    }

The main function takes args, which contains the arguments from the command line.

Reading command-line arguments

We will be taking two arguments from the command line:

  • The name of the CSV file to read
  • The column number to find unique entries from

The following code block shows how to read arguments passed from the command line:

    // Get command line input
    if (args.size != 2) {
      println("Usage: csv_filename column_number")
      return
    }
    val fileName = args[0]
    val columnNumber...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image