我如何大写字符串的第一个字符,而不改变任何其他字母的情况?

例如,“this is a string”应该给出“this is a string”。


当前回答

这个代码适用于我。

String name = 'amina';    

print(${name[0].toUpperCase()}${name.substring(1).toLowerCase()});

其他回答

你可以用这个包 ReCase 它为您提供了各种大小写转换功能,如:

snake_case dot.case 路径/案例 param-case PascalCase 消息头实例中 标题的情况 camelCase 句子中 CONSTANT_CASE ReCase sample = new ReCase('hello world'); 打印(sample.sentenceCase);//打印'Hello world'

这个代码适用于我。

String name = 'amina';    

print(${name[0].toUpperCase()}${name.substring(1).toLowerCase()});

简单,没有任何扩展:

title = "some title without first capital"

title.replaceRange(0, 1, title[0].toUpperCase())

// Result: "Some title without first capital"

final helloWorld = 'hello world'.toUpperCase(); 文本(helloWorld);

尝试此代码大写的任何字符串的第一个字母在飞镖扑动

Example: hiii how are you

    Code:
     String str="hiii how are you";
     Text( '${str[0].toUpperCase()}${str.substring(1)}',)`

Output: Hiii how are you