如何使用扩展在单词末尾添加冒号

huangapple go评论56阅读模式
英文:

How to add colon to the end of the word using extension

问题

我想要在给定位置使用扩展将冒号添加到Dart单词中,就像这样(在Flutter中)。
示例:

Name: 和 Password:

Name:
Password:
No:
Price:

我们在Dart中使用大小写字母,就像我尝试在冒号(:)中使用的那样,类似于这种类型的任何单词并使用冒号扩展,我如何创建这个,请帮助我...

英文:

13

I would like to add colon to a Dart word in a given position using extension, exactly like this (In flutter).
example:

Name: and Password:

Name:
Password:
No:
Price:

we are use Uppercase and Lowercase in dart same as I try use in colon(:) same like this type any word and use colon extension how can I create this please help me...

答案1

得分: 0

创建一个新的字符串扩展,如下所示:这将使您的单词首字母大写,并在单词末尾添加冒号:

extension StringExtension on String {
  String toCapitalized() => length > 0
      ? '${this[0].toUpperCase()}${substring(1).toLowerCase()}:'
      : '';
}

使用:

Text("name".toCapitalized()),
Text("password".toCapitalized()),
英文:

Create new extension for string like below: This will capitalised your word and add colon at end of the word:

extension StringExtension on String {
  String toCapitalized() => length > 0
      ? '${this[0].toUpperCase()}${substring(1).toLowerCase()}:'
      : '';
}

Use:

Text("name".toCapitalized()),
Text("password".toCapitalized()),

huangapple
  • 本文由 发表于 2023年7月20日 14:39:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727275.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定