本文介绍了在Regex.Split()中获取Unterminated []设置异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 
$


我正在"解析"[]" - 未终止[]设置。" 使用正则表达式为下面的字符串拆分字符串时出现异常

Hi All, 

I am getting "parsing "[]" - Unterminated [] set."  exception while splitting string with Regular expression for below string

string studentinfo = "Student Info : \n[]Student Attendance \n[]Student Lunch Time\n[]Student Play time\n[]Student Library time, \nStudent Class room Info : \n[]Maths Class Time \n[]Physics Class Time \n[]GK Class Time \n\nFinal Report";
            List<string> pattern = new List<string>();
            pattern.Add("[]");
            string[] studentRecord = null;

            try
            {
                if (studentinfo != null && pattern != null)
                {
                    studentRecord = Regex.Split(studentinfo, @"" + pattern[0] + "", RegexOptions.IgnoreCase).Where(s => s.Contains(pattern[0]) && s != string.Empty).ToArray().Select(p => p.Replace(pattern[0], string.Empty)).ToArray();
                }
            }
            catch (Exception e)
            {

            }


这里的错误是什么?请帮帮我



谢谢你


Chandu

what is the mistake here? please help me

Thanks

Chandu

推荐答案

所以你需要逃避它们:

 pattern.Add(@"\[\]");

仍然不确定这会产生你所追求的结果。您可能需要解释您要做的事情。

Still not sure this will produce the results you are after though. You may have to explain what you're trying to do.


这篇关于在Regex.Split()中获取Unterminated []设置异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 21:32