package com.common.commonlib.utils

import android.text.TextUtils

/**
 * 字符串工具类
 */
class StringUtils {

    /**
     * 将字符串List转化为用 | 分割的字符串
     */
    fun getStringSeparateByLine(list: List<String>): String {
        var result = ""
        for (item in list.withIndex()) {
            result = if (item.index == (list.size - 1)) {
                "$result${item.value}"
            } else {
                "$result${item.value}|"
            }
        }
        return result
    }

    /**
     * 将 | 分割符转化为list
     */
    fun getListByString(source: String): List<String> {
        if (TextUtils.isEmpty(source)) {
            return ArrayList()
        }
        return source.split("|")
    }
}