您当前的位置: 首页 >  十幺卜入 unity

Unity3d C# 去除字符串结束符\0\0\0\0\0的方式

十幺卜入 发布时间:2021-04-19 16:49:00 ,浏览量:4

前言

通过字节数组转字符串,产生了一串的\0\0\0\0\0的尾巴,由于需要进行字符串判断,所以需要将它去除,尝试了网上的很多方法都不行,经过摸索在Unity中可行的方式,用正则替换实现了。

解决方式

  string str = "acccc\0\0\0\0\0a";
  string s2 = str.Replace("\0", "");

测试过程

测试代码:

using UnityEngine;
public class Test : MonoBehaviour
{
    void Start()
    {
        string str = "acccc\0\0\0\0\0a";
        string s1 = str.Replace("\\0", "");
        string s2 = str.Replace("\0", "");
        string s3 = str.Trim();
        string s4 = str.TrimEnd('\0');
        string s5 = str.Replace(@"\0", "");
    }
}

测试结果:

关注
打赏
查看更多评论

十幺卜入

暂无认证

  • 4浏览

    0关注

    76博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录