String.Remove/String.Replace ain't working?

Hi everyone!
Could somebody tell me why can't I remove parts from my string?

Resuming: Basically I have these string _data which goes to my database and gave me that value.

string _data = "2019/1/13 00:00:00"

_data.Remove(10, 8);
_data.Remove(10);
_data.Replace(" 00:00:00", "");

I already tried to use all of this methods but, for some reason, they are not working. What am i doing wrong?

P.S: I am doing this inside a foreach

Best Answer

  • LucasZhangLucasZhang Xamurai
    Accepted Answer

    Because String.Remove method returns a new string. It doesn't change original one.

    string _data = "2019/1/13 00:00:00"
    
    string _newData =_data.Remove(10, 8);
    

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai
    Accepted Answer

    Because String.Remove method returns a new string. It doesn't change original one.

    string _data = "2019/1/13 00:00:00"
    
    string _newData =_data.Remove(10, 8);
    
  • ricardoventuraricardoventura Member ✭✭

    @LucasZhang said:
    Because String.Remove method returns a new string. It doesn't change original one.

    string _data = "2019/1/13 00:00:00"
    
    string _newData =_data.Remove(10, 8);
    

    Ohh woaw. Didn't think about having a new string.... thanks for your replying! That helped! Much love

Sign In or Register to comment.