gpt4 book ai didi

c# - 从字符串中获取特定字符后的字符

转载 作者:行者123 更新时间:2023-11-30 13:31:25 24 4
gpt4 key购买 nike

我需要在字符串中的某些字符匹配后获取字符。请考虑我的输入字符串和预期的结果字符集。

示例字符串

*This is a string *with more than *one blocks *of values.

结果字符串

Twoo

我做到了

string[] SubIndex = aut.TagValue.Split('*');
string SubInd = "";
foreach (var a in SubIndex)
{
SubInd = SubInd + a.Substring(0,1);
}

对此的任何帮助将不胜感激。

谢谢

最佳答案

LINQ解决方案:

var str = "*This is a string *with more than *one blocks *of values.";
var chars = str.Split(new char[] {'*'}, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.First());
var output = String.Join("", chars);

关于c# - 从字符串中获取特定字符后的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21548108/

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