Swift 日本語と英語が混じっても表示上同じくらいの長さにしたい
Example
🎬ブラックウィドウDisney+プレミア公開
1:00 England 2-0 Germany
↓
🎬ブラックウィドウDisney…
1:00 England 2-0 Germany
コード
func abbreviationScheduleText(_ text: String) -> String {
var count = 0
var index = 0
var result = ""
for c in text {
count = count + (String(c).data(using: .ascii, allowLossyConversion: false) != nil ? 1 : 2)
result.append(c)
index = index + 1
if count >= 24 {
break
}
}
if index < text.count {
result = result + "…"
}
return result
}





