3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Flutter】全角・半角判定しながら文字数カウント

Last updated at Posted at 2022-04-14
import 'package:charset_converter/charset_converter.dart';

onChanged: (String value) async {
  final int _StringCount = 0;
  await Future.forEach(value.runes, (int rune) async {
    List<int> bytes = await CharsetConverter.encode('cp932', String.fromCharCode(rune));
    _StringCount += bytes.length;/// 2 = 全角, 1 = 半角
  });
  setState(() {
    _fullCount = _StringCount / 2;///全角文字数
  });
},
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?