>> x = "The flying pig" The flying pig >> x[3:5] e f >> x[1] = "E"; Ehe flying pig >> x[1:3] = "the"; the flying pig >> x[$-2:$] = "wig" the flying wigNote that the $ sign when appearing in an index expression represents the length of the variable being indexed, therefore x[$] refers to the last character of the string.
ASCII values can be assigned to one or several characters of a string. For example,
>> x = "The flying pig" >> x[12] = 119; >> x The flying wig >> x[12:14] = [98, 112, 103]; >> x The flying bug"Note that the value assigned to string must be valid ASCII value; in particular, zero value is not allowed.