gpt4 book ai didi

c# - 以大写形式显示句子中的最后一个单词

转载 作者:行者123 更新时间:2023-11-30 17:37:59 25 4
gpt4 key购买 nike

我想以大写形式显示句子中的最后一个单词,但它只会选择最后一个或大写。

这是我的代码:

 string sentence = "write LINQ queries to do the following";
string[] words = sentence.Split(' ');
IEnumerable<string> query =
from w in words
select w.Last()
.ToUpper;

最佳答案

你可以使用 linq:

var res = sentence.Split(' ').Last().ToUpper();

或者更高效一点:

var res = sentence.Substring(sentence.LastIndexOf(' ') + 1).ToUpper()

关于c# - 以大写形式显示句子中的最后一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37187124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com