C#与U3D中字符串尾0

        static void TestChar0()
        {//注意字符串中0和\0的区别,如 s1="h0ello", s2 = "h\0ello"
            //s2中的\0是字符串结尾符,除了C#不把它作为结束符外,其它语言都把它作为结束符,如U3D,LUA,C/C++等
            //而s1中的0仅是一个字符0而已,字符0的ASCII值是0X31=49,'\0'的ASCII值是0
            //注意这两种0在C#和U3D的API之间切换时容易造成BUG,如:
            //1, debug.log(s1): "h0ello"
            //2,debug.log(s2): "h"
            var s = "hello";
            s += 0 + ",world";
            var s1 = "hello";
            s1 += (char)0 + ",world";
            var s2 = "hello";
            s2 += '\0' + ",world";
        }

 

posted @ 2018-01-16 17:45  时空观察者9号  阅读(242)  评论(0)    收藏  举报