c# – 从String中的某个字符后获取字符
发布时间:2020-12-15 23:42:12 所属栏目:百科 来源:网络整理
导读:我需要在字符串中的某个字符匹配后获取字符.请考虑我的输入字符串与预期的结果字符集. 示例字符串 *This is a string *with more than *one blocks *of values. 结果字符串 Twoo 我做到了这一点 string[] SubIndex = aut.TagValue.Split('*'); string SubInd
我需要在字符串中的某个字符匹配后获取字符.请考虑我的输入字符串与预期的结果字符集.
示例字符串 *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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |