gpt4 book ai didi

c# - 使字符串中的小写大写和大写小写

转载 作者:行者123 更新时间:2023-12-05 08:46:23 26 4
gpt4 key购买 nike

我一直在努力使用 .ToUpper 和 .ToLower 将字符串中的单词转换为相反的大小写。

示例 1:

Input: hello WORLD
Output: HELLO world

示例 2:

Input: THIS is A TEST
Output: this IS a test

最佳答案

C#

string a = "hello WORLD";

string b = new string(a.Select(_ => char.IsLower(_) ? char.ToUpper(_) : char.ToLower(_)).ToArray());

关于c# - 使字符串中的小写大写和大写小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69738834/

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