Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Cypher using .Replace/Use a list to remove what I'm replacing during run time?

Discussion in 'Scripting' started by Mothman_exe, Oct 16, 2023.

  1. Mothman_exe

    Mothman_exe

    Joined:
    Jun 3, 2023
    Posts:
    2
    Hi, kind of a beginner here!!

    I'm currently adding to my dialogue system some code that will let me feed my text through a cypher before displaying it when I have a bool checked. It's for a hangman sorta style visual novel I'm making for school.

    The base replacing the text and turning it on and off is working pretty well but now I need to be able to remove each replace.(' ',' ') bit when a bool is checked (on my dialogue object, where YesCode is) so the dialogue can become more readable over time.

    Is there a way to do this? using a list that changes over runtime or something? I don't really know where to start here.

    Any suggestion/help would be greatly appreciated!!

    (See code below and my dialogue object set up) Screenshot (361).png Screenshot (363).png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,150
    You can do some of this with regular expressions (regex), at least to identify parts of the text you're interested in.

    Otherwise you're just doing (and redoing) the decryption and displaying the partial result. This is just basic string manipulation, absolutely nothing to do with Unity.

    Another handy C# class for this might be the StringBuilder class, again nothing at all to do with Unity.