I wanted to replace a certain part of my string into something else. So I started playing with C# strings, and came across the Replace method.
So I tried doing it using this:
void DisplayLines(string speakerName, List<string> lines)
{
List<string> newLines;
newLines = lines;
for(int i = 0; i < newLines.Count; i++)
{
if(newLines*.Contains("<active_char>"))*
-
{*
string newLine = newLines*.Replace(“<active_char>”, activeChar);
_ newLines = newLine;
}
}*_
* dialogueDisplay.SetTextToDisplay(newLines);*
}
For example, currently my lines is set to “< active_char > is currently speaking”, and in the game my active character is named “Elsa”. So, it would work for the first time, and would display “Elsa is currently speaking”.
However, my variable lines gets replaced as well, it gets overwritten. So the next time I call the same set of lines, the “< active_char >” part has already been replaced by the previous call. So if the active character has now been set to “Anna”, it would still display “Elsa”. What can I do to avoid this? Or is there another string method that can actually do what I’m trying to do?
Hope I explained it well enough. Thank you for your help!