D 语言实现字符串单词首字母大写 - 相当于 PHP 的 Str::title 函数
D 语言实现字符串单词首字母大写 - 相当于 PHP 的 Str::title 函数
本教程展示如何使用 D 语言实现将字符串中每个单词的首字母大写,类似于 PHP 的 Str::title 函数功能。
PHP 代码:
use Illuminate\Support\Str;
$converted = Str::title('a nice title uses the correct case');
// A Nice Title Uses The Correct Case
D 语言实现代码:
import std.stdio;
import std.string;
void main() {
string input = 'a nice title uses the correct case';
string[] words = input.split(' ');
foreach (i, word; words) {
words[i] = word.capitalize();
}
string output = words.join(' ');
writeln(output);
}
输出结果:
A Nice Title Uses The Correct Case
原文地址: https://www.cveoy.top/t/topic/odap 著作权归作者所有。请勿转载和采集!