All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.binaryfoo.decoders.CsvReader.kt Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
package io.github.binaryfoo.decoders

import io.github.binaryfoo.res.ClasspathIO
import java.util.*

/**
 * Read a CSV into a map. Say alpha to numeric code.
 *
 * @param fileName CSV file with source data
 * @param codeLength length of first column in source file (followed by comma, space and alpha-description of the code
 */
fun csvToMap(fileName: String, codeLength: Int): Map {
    val map = HashMap()
    ClasspathIO.readLines(fileName).forEach { line ->
        val numeric = line.substring(0, codeLength)
        val alpha = line.substring(codeLength + 2)
        map.put(numeric, alpha)
    }
    return map
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy