Change specific characters color in text

I want to change a specific letters color in my text.
Right now im working with this:
textToWrite.text = textToWrite.text.Replace(textToWrite.text[charBeingTyped].ToString(), “color=#ffffffxx>/color”);

The textToWrite is the text i want to edit.
The charBeingTyped is a variable containing the position of the letter in the text.

So i want the letter charBeingTyped to become the chosen color.
I need something like this pseudo code: “color=#ffffffxx"The charBeingTyped/color”);

But i can’t really figure out how to put a variable inside quote symbols.

EDIT: I removed the “< >” from the color code, since the forum just deletes it.

Here’s how you can do it:

public UnityEngine.UI.Text myText;
// Get index of character.
int charIndex = myText.text.IndexOf ("S");
// Replace text with color value for character.
myText.text = myText.text.Replace (myText.text [charIndex].ToString (), "<color=#000000>" + myText.text [charIndex].ToString () + "</color>");

I came up with a rather convoluted way to achieve it but it works.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Test : MonoBehaviour
{

List <string> strList = new List<string>();
string finalString;	

void Start()
{
	Debug.Log(FormatText("testtext", "00100100"));
}

string FormatText(string normalWord, string positions)
{	

	finalString = null;
	strList.Clear();
	string positionString = positions.ToString();
	for(int i=0; i<normalWord.Length; i++)
	{	

		if(int.Parse(positions*.ToString())==1)*
  •   	{*
    

_ strList.Add(normalWord*+“”);_
_
}_
_
else*_
* {*
_ strList.Add(“<color=yellow>”+normalWord*+“”);
}
}
for(int i=0; i<strList.Count;i++)
{
finalString+=strList;
}
return finalString;
}
}*

The FormatText() method takes the string you want to edit and a position string. 0 will color the text yellow and 1 will keep it as it is. So it your string is “foo” and you want the ‘oo’ to be yellow, pass in ‘foo’ as the first parameter and ‘100’ as the second one._