0
\$\begingroup\$

i tried to look up my question but didn't really find an answer that works for my situation.

I'm using this unity asset called Dialoguer to create interactive dialogues. What I'm trying to do is to pass a test in the asset, that test if a condition is true, then replace a specific part of the output text.

My problem right now is I can't find the right code to check for a specific string and replace it with another.

Please help

\$\endgroup\$
1
  • \$\begingroup\$ So you want to run a simple search&replace on the text of a Text UI element? \$\endgroup\$ Commented Apr 3, 2016 at 9:45

1 Answer 1

0
\$\begingroup\$

This answer goes the normal Unity way and disregards that you use the 3rd party Dialoguer system. It might provide a better way to do this or might even conflict with this method, but please forgive me that I won't pay $30 just to better answer this one question. But I noticed that the marketing bullet points for it mentions an "integrated variable system" which might help you to do what you want to do.


The text of an UI Text component is stored in the property text. Its value is a string, which is one of the basic classes of the C# language, so we need to head to the Microsoft Developers Network to read its documentation. There we find the method Replace(string oldValue, string newValue), which "Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string". So all you need to do in your script is get a reference to your Text UI element and then do:

 textUIElmenent.text = textUiElement.text.Replace("oldString", "newString");
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.