我如何大写字符串的第一个字符,而不改变任何其他字母的情况?
例如,“this is a string”应该给出“this is a string”。
我如何大写字符串的第一个字符,而不改变任何其他字母的情况?
例如,“this is a string”应该给出“this is a string”。
当前回答
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
你可以用这个包 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()});
下面是我使用dart String方法的答案。
String name = "big";
String getFirstLetter = name.substring(0, 1);
String capitalizedFirstLetter =
name.replaceRange(0, 1, getFirstLetter.toUpperCase());
print(capitalizedFirstLetter);
final helloWorld = 'hello world'.toUpperCase(); 文本(helloWorld);