- Home /
 
replacing a character in a String
how to, for example
do this:
function testReplace(){
var sentence = "roma";
sentence[0] = "c";.
print(sentence); //and expect "coma"
}
 
               
               instead, there's an unity error that says Chars in String are read only.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by spinaljack · Sep 26, 2010 at 01:01 AM
There might be an easier method but you can remove the characters you don't wont and then insert the correct ones:
function testReplace(){
   var sentence = "roma";
   sentence = sentence.Remove(0,1);
   sentence = sentence.Insert(0,"c");
   print(sentence); //and expect "coma"
}
 
              Your answer