Change A Character In A String Using Actionscript

前端 未结 4 1779
悲哀的现实
悲哀的现实 2021-01-19 00:09

What is the opposite of String.charAt()??

If I Have a string:

var Str:String=\"Hello World\";

How do I change the 5th chara

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 00:56

    you cannot set any characters. Strings in ECMAScript (including ActionScript) are immutable. One thing you can do is to construct a new string containing the desired characters, as proposed here.

    However, if you plan to modify the string a lot, the best is to rather have an array of characters, that you can mutate at will. When you need to print it, you simply join it with "" as separator.

    greetz
    back2dos

提交回复
热议问题