在一个输入框中输入多个名字时,客户可能会用不同的符号来分隔,如下示例:张三、李四
张三,李四
张三。李四
张三,李四
张三/李四

标点符号不同,且分中文和英文两种形式。
现在需要分隔这些名字,来和数据库中存在的记录做比较,看有没有重复记录。求助:如何分隔这些名字?

解决方案 »

  1.   

    char[] sep={',',',','/','.','。','、'};
    string[] strs="张三/李四".Split(separator, StringSplitOptions.RemoveEmptyEntries);
    //得到一个数组,0元素为"张三",1元素为"李四",下面你该干嘛干嘛吧
      

  2.   

    char[] separator={',',',','/','.','。','、'};
    string[] strs="张三/李四".Split(separator, StringSplitOptions.RemoveEmptyEntries);
      

  3.   

    只要名字不会出现英文,就可以用这个正则表达式把名字匹配出来[\u4e00-\u9fa5]*
      

  4.   

    StringCollection resultList = new StringCollection();
    try {
    Regex regexObj = new Regex(@"[\u4e00-\u9fa5]*");
    Match matchResult = regexObj.Match("张三、李四");
    while (matchResult.Success) {
    resultList.Add(matchResult.Value);
    matchResult = matchResult.NextMatch();

    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }