String documentation and change one character

The documentation (Unityscript) is sadly lacking about String - I believe you have to look up .NET string to find what functions are available - would be nice to have more in the docs - which only mention length!

Anyway - is there an easy way to change one character in a string without breaking it up and building a new one?

thanks

No method to do strictly that I believe. Probably just write your own function like this:

string test = "asdf";
string replaced = ChangeCharacter(test, 2, "|");
Debug.Log("REPLACED: " + replaced);
private string ChangeCharacter(string text, int character, string newCharacters)
{
    return text.Remove(character, 1).Insert(character, newCharacters);
}

Strings are char arrays, unfortunately read-only, but you can replace a single character of a StringBuilder, so you can convert to a StringBuilder and back:

var myString = "abcdefg";
var sb = System.Text.StringBuilder(myString);
sb[2] = "z"[0];
myString = sb.ToString();

–Eric