Change a character in a string using ActionScript

What is the opposite String.charAt()??

If I have a line:

var Str:String="Hello World";

How to change the 5th character, for example, from '' to '_'?

I can get the 5th character as follows:

var C:String=Str.charAt(5);

But how to set the 5th character?

Thanks in advance.

+5
source share
4 answers

There are many ways to trick this cat. One, from my head, will include String.substr:

var Str:String="Hello World"
var newStr:String = Str.substr(0,5) + "_" + Str.substr(6);

or, as above, but more generalized:

function setCharAt(str:String, char:String,index:int):String {
    return str.substr(0,index) + char + str.substr(index + 1);
}
+10
source

. ECMAScript ( ActionScript) . , , , , .

, , , . , join "" .

Greetz
back2dos

+2

, , . , 4- B "w".

B = B.replace(B.charAt(4), "w");

flash cs4 actionscript 3.0, -, . , .

+1
//Replacing "/" with "-"
var str:String = "he/ll/o"
str = str.split("/").join("-"); //str = he-ll-o
+1

All Articles