毕业设计想做一个考试系统,达到一个批量导入考题的功能。。2008年奥运会在哪里举行? (知识点:奥运会-难易指数:1)选择题
A.中国(正确) B.美国 C.英国2008年奥运会将在什么时间举行?(知识点:奥运会举办时间-难易指数-1)填空题
8月8日要把以上内容分割成以下格式:问题1:2008年奥运会在哪里举行?
知识点:奥运会
考题类型:选择题
答案:A.中国 B.美国 C.英国
正确答案:A问题2:2008年奥运会将在什么时间举行?
知识点:奥运会举办时间
考题类型:填空题
正确答案:8月8日
就上面的样子,怎么才能实现。

解决方案 »

  1.   

    使用正则表达式进行字符串提取。
    参考以下代码:// Regex_extract.cpp
    // compile with: /clr
    #using <System.dll>using namespace System;
    using namespace System::Text::RegularExpressions;int main()
    {
        array<String^>^ address=
        {
            "[email protected]",
            "[email protected]",
            "treyresearch.net",
            "[email protected]"
        };    Regex^ emailregex = gcnew Regex("(?<user>[^@]+)@(?<host>.+)");    for (int i=0; i<address->Length; i++)
        {
            Match^ m = emailregex->Match( address[i] );
            Console::Write("\n{0,25}", address[i]);        if ( m->Success ) 
            {
                Console::Write("   User='{0}'", 
                m->Groups["user"]->Value);
                Console::Write("   Host='{0}'", 
                m->Groups["host"]->Value);
            }
            else 
                Console::Write("   (invalid email address)");
            }    Console::WriteLine("");
        return 0;
    }
      

  2.   

    1、读写文本文件(.txt .ini .xml 等);
    2、[写入库],显示在页面(窗体);
    3、答完,计分;
      

  3.   


    private void getText(string text)
    {
        string temp = "";
        MatchCollection mats = Regex.Matches(text, @"^.*?知识点.*?\r\n.*?\r\n", RegexOptions.Multiline);
        int count = 1;
        foreach (Match mat in mats)
        {
            temp += "题目" + count.ToString() + ":" + Regex.Match(mat.Value, @"^.*?(?=(\(知识点))").ToString()+"\r\n";
            temp += Regex.Match(mat.Value, @"知识点:.*?(?=(-))").ToString() + "\r\n";
            if (Regex.Match(mat.Value, @"(?<=(\))).*").ToString().Trim() == "选择题")
            {
                temp += "考题类型:" + "选择题" + "\r\n";
                temp += "答案:" + Regex.Match(mat.Value, @"(?<=\n).*").ToString().Replace("(正确)", "")+"\r\n";
                temp += "正确答案:" + Regex.Match(mat.Value, @"\w+(?=.*正确)").ToString()+"\r\n";
            }
            if (Regex.Match(mat.Value, @"(?<=(\))).*").ToString().Trim() == "填空题")
            {
                temp += "考题类型:" + "填空题" + "\r\n";
                temp += "正确答案:" + Regex.Match(mat.Value, @"(?<=\n).*").ToString() + "\r\n";
            }
            //temp += Regex.Match(mat.Value, @"(?<=\. ).*").ToString() + "\r\n";        //temp += Regex.Match(mat.Value, @"(?<=switchport access vlan )\d*").ToString() + "\r\n";
            count++;
        }
        return temp ;}
      

  4.   

    String conStr;
    using(StreamReader sr= new StreamReader("路径"))
    {
            while (sr.Read(content, 0, content.Length) > 0)
            {
              conStr += encoding.GetString(content);
            }}
    读文件
    using(StreamWriter sr= new StreamWriter("路径"))
    {
        sr.Write(content, 0, content.Length);
    }
    写文件
    我只写个txt 的文件
      

  5.   


    List<String> lis= new List<string>();
    lis.add("问题1:2008年奥运会在哪里举行?");
    lis.add("知识点:奥运会" );
    lis.add(问题1:2008年奥运会在哪里举行?);
    lis.add("考题类型:选择题 ");
    lis.add("答案:A.中国 B.美国 C.英国 ");
    lis.add("正确答案:A ");
    lis.add("问题2:2008年奥运会将在什么时间举行?");
    lis.add("知识点:奥运会举办时间");
    lis.add("考题类型:填空题 ");
    lis.add("正确答案:8月8日 ");using(StreamWriter sr= new StreamWriter("路径")) 

       for(int i=0;i<lis.Count;i++)
        {
          sr.Write(lis[i], 0, lst[i].Length); 
        }
        

    //问题1:2008年奥运会在哪里举行? 
    //知识点:奥运会 
    //考题类型:选择题 
    //答案:A.中国 B.美国 C.英国 
    //正确答案:A //问题2:2008年奥运会将在什么时间举行? 
    //知识点:奥运会举办时间 
    //考题类型:填空题 
    //正确答案:8月8日 
      

  6.   

    读文件就循环读出来装到lst泛型里