Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Replace string with a backspace (or delete the empty space)

Discussion in 'Scripting' started by saifshk17, Mar 19, 2019.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    Hi,

    Is it possible to delete a string and replace it with a backspace so there are no empty space?
    Something like this:
    Code (CSharp):
    1. Description[i].text = Description[i].text.Replace("<li>","");
    Thanks
     
    bravophantom likes this.
  2. wileyjerkins

    wileyjerkins

    Joined:
    Oct 13, 2017
    Posts:
    77
    string test = "Hello World!";
    test = test.Replace(" ", "");

    output should be HelloWorld!
     
    bravophantom likes this.
  3. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    That replaces every empty space but I just wanted a specific one
     
    bravophantom likes this.
  4. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Your question was difficult to understand, and it is incorrect. You do not want to replace a space with a backspace character, you want to shorten the string if it ends on whitespace.

    There is the Trim method available that removes leading and trailing characters from a string.

    Hope this helps,
    -ch
     
    bravophantom likes this.