方法string.Replace()不起作用 [英] Method string.Replace( ) doesn't work

查看:255
本文介绍了方法string.Replace()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public string Generate()
    {
        RandomNumberGenerator rdng = new RNGCryptoServiceProvider();
        byte[] bytes = new byte[40];

        rdng.GetBytes(bytes);

        string a = Convert.ToBase64String(bytes); 

        a.Replace("=", "r");
        a.Replace("+", "t");

        return a;
    }

a=43TvtRvrTrt54g5gtbrTTBR45iu+zqbB03gXej== ;

再次在a.Replace()之后:

a=43TvtRvrTrt54g5gtbrTTBR45iu+zqbB03gXej== ;

我想在我的C#项目中生成唯一的值. 一切都很棒. 但是当我想调用string.Replace()时,它不起作用. 此方法前后的值相同. 为什么?

I want to generate unique value in my C# project. Everything is great. But When I want to call string.Replace(), it doesn't work. Values after and before this method are the same. Why ?

推荐答案

replace方法返回一个新的字符串对象,它不会修改现有的字符串.以下语句应该起作用:

The replace method returns a new string object, it does not modify the existing string. The following statement should work:

a = a.Replace("=", "r");

这篇关于方法string.Replace()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆