package com.base.appzxhy.utils

import android.graphics.Color
import android.text.SpannableString
import android.text.style.ForegroundColorSpan

object SpannableUtils {


    fun highlightText(fullText: String, targetText: String, color: Int = Color.RED): SpannableString {
        val spannableString = SpannableString(fullText)
        val startIndex = fullText.indexOf(targetText)

        if (startIndex != -1) { // 确保子串存在
            val endIndex = startIndex + targetText.length
            spannableString.setSpan(
                ForegroundColorSpan(color),
                startIndex,
                endIndex,
                SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
            )
        }

        return spannableString
    }
}