Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

closed as off-topic by Josh Petrie Apr 3 at 13:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

    
So you want to run a simple search&replace on the text of a Text UI element? – Philipp Apr 3 at 9:45
up vote 0 down vote accepted

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");
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.