Replace value in string c# not working

前端 未结 5 2031
梦如初夏
梦如初夏 2020-12-04 03:37
            
                
                   


        
相关标签:
5条回答
  • 2020-12-04 04:01

    Because string.Replace does not modify the string, it returns a new one

    _viewPath = _viewPath.Replace("tbody", "table");
    

    will do the trick.

    0 讨论(0)
  • 2020-12-04 04:02

    You should do:

    _viewPath = _viewPath.Replace("tbody", "table");
    
    0 讨论(0)
  • 2020-12-04 04:03

    Strings are immutable. That means you don't modify them - .Replace returns a NEW string. Try this:

    _viewPath = _viewpath.Replace("tbody", "table");
    
    0 讨论(0)
  • 2020-12-04 04:14

    Replace is a function actually, and does return the results. You have to do it this way :

    var Result = _viewPath.Replace("tbody", "table");
    

    where Results contains the result of the transformation.

    0 讨论(0)
  • 2020-12-04 04:18

    You should save the result of Replace: _viewPath = _viewPath.Replace("tbody", "table");

    0 讨论(0)
提交回复
热议问题