如何使用linq删除列表中的特殊字符集前缀 [英] How to remove special character set prefix in list using linq

查看:109
本文介绍了如何使用linq删除列表中的特殊字符集前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 

Hi All, 

请帮我删除下面字符串列表中的特殊字符集前缀。 

Please help me to remove special character set prefix in below string list here. 

我在这里有以下列表。 

i have below list here. 

 List<string> removalPattern = new List<string>();
            removalPattern.Add(@"[__]");
            string studentInfo = "[__] Student Attendance \n[__] Student Lunch Time\n(**) Parents Meeting Date \n[__] Student Play time\n[__] Student Library time, \n(**) Parents Observation \n";
            var StudentList = Regex.Split(studentInfo, "\n").Where(s => s.Contains(removalPattern[0]) && s != string.Empty).ToArray();



$'b $ b

'StudentList'我得到的每个字符串都带有"[__]"字首。我不需要这个前缀。请帮我删除列表中每个字符串的前缀。

in 'StudentList' i am getting each string with "[__]" prefix. i don't need this prefix. please help me to remove this prefix for each string in list.

谢谢,

Chandu

推荐答案

要从字符串前面删除任意字符,请使用
TrimStart
。要从后面删除,请使用
TrimEnd
。要从两者中删除,请使用
修剪

To remove an arbitrary character from the front of a string use TrimStart. To remove from the back use TrimEnd. To remove from both use Trim.

var studentList = from s in Regex.Split(...)
                  select s.TrimStart('_');


 


这篇关于如何使用linq删除列表中的特殊字符集前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆