且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用特殊字符分割文本

更新时间:2023-12-05 13:30:22

为什么不那样尝试

Why dont you try like that

string ss = "}xxxix,{ †‡ƒ«. :›¢øñ";
          char[] c = { ''}'', ''{'' };
          ss.Split(c);


我不会使用正则表达式,只使用String.Split两次:
I wouldn''t use a regex, just String.Split twice:
string text = "›¢øñ}xxxix,{ †‡ƒ«. :›¢øñ";
string[] withoutClose = text.Split(''}'');
if (withoutClose.Length == 2)
    {
    string[] withoutOpen = withoutClose[1].Split(''{'');
    if (withoutOpen.Length == 2)
        {
        string start = withoutClose[0];
        string middle = withoutOpen[0];
        string end = withoutOpen[1];
        }
    }