Change part of a string [Solved]

I want to change a part of a string like:

Hello (username), this is an example.


Hello exapleusername, this is an example.

I tried:

sentence = xyz; 
        string[] array = xyz.Split(' ');
        foreach (string token in array)
            if(Playername == token)
                //change this token

but i dont know how to change the token.
Can you help me?

Why making things complicated ?

string sentence = "Hello (username)" ;
string output = sentence.Replace( "(username)", "Bob" ) ;
// output = "Hello Bob" ;

However, if you don’t know the value between your parenthesis, then use regular expressions :

string sentence = "Hello (something)" ;
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\\(\\w+\\)") ;
string output = regex.Replace( sentence, "Bob" ) ;
// output = "Hello Bob" ;

So let me understand you correctly.

Lets say the player enters his/her username into an input field you want to display it as a string like following:

[“Hello”] + [“username from inputfield”]

So I think it will look similar to something like this:

public Inputfield usernameInputfield;
public string storeUsername;
public Text outputContainer;
//So lets say you click on a button or something you willdo:
storeUsername = usernameInputfield.text;
//Your string ["storeUsername] will then be = to the text entered into the ["usernameInputfield"]
//Lets say we want to test the result if we click on a button or something we will do:
Debug.Log("Hello, " + storeUsername);
//To get it in a string:
string newString = "Hello, " + storeUsername;
//You can then replace the text of ["outputContainer"] like the following:
outputContainer.text = "Hello, " + storeUsername;
outputContainer.text = newString;

I hope that this is what you are looking for.

Am just adding how I split my string here hopefully it helps somebody else
The original string is “Drag @ to Square” replacing the @ with other text

private void substituteCharInStringForNewWord(string myCommand)
                string[] splitArray = myCommand.Split(char.Parse("@"));
                Debug.Log("Split array count = " + splitArray.Length  +"Command" + myCommand);
                string tempO = splitArray[0];  ///Drag
                Debug.Log("splitArray[0] " + tempO);
                string tempTwo = splitArray[1]; /// to Square
                Debug.Log("splitArray[1] " + tempTwo);
                ///Drag colour to Square
                reSubtitutedString = tempO + newColourmatchThisToLinkedDropTile + tempTwo;
                Debug.Log("CombinedString" + reSubtitutedString);