Least used delimiter character in normal text < ASCII 128

后端 未结 14 1454
执念已碎
执念已碎 2020-12-23 19:00

For coding reasons which would horrify you (I\'m too embarrassed to say), I need to store a number of text items in a single string.

I will delimit them using a char

14条回答
  •  庸人自扰
    2020-12-23 19:11

    For fast escaping I use stuff like this: say you want to concatinate str1, str2 and str3 what I do is:

    delimitedStr=str1.Replace("@","@a").Replace("|","@p")+"|"+str2.Replace("@","@a").Replace("|","@p")+"|"+str3.Replace("@","@a").Replace("|","@p");
    

    then to retrieve original use:

    splitStr=delimitedStr.Split("|".ToCharArray());
    str1=splitStr[0].Replace("@p","|").Replace("@a","@");
    str2=splitStr[1].Replace("@p","|").Replace("@a","@");
    str3=splitStr[2].Replace("@p","|").Replace("@a","@");
    

    note: the order of the replace is important

    its unbreakable and easy to implement

提交回复
热议问题