unity replace a text in a string 1

unity replace a text in a string

public string strOne = "Hello World";
public string strTwo = "World";

public void ReplaceStrTwoFromStrOne()
{
	strOne = strOne.Replace(strTwo, "everyone"); //strOne = "Hello everyone" now
}

Here is what the above code is Doing:
1. We have two strings, strOne and strTwo.
2. We call the Replace method on strOne, passing in strTwo and the string we want to replace it with.
3. The Replace method returns a new string with the replacement made.
4. We assign the new string to strOne.

The Replace method is a method of the string class. It takes two parameters: the string to replace and the string to replace it with.

The Replace method returns a new string with the replacement made. It does not modify the original string.

Similar Posts