更改字符在字符串中使用ActionScript [英] Change A Character In A String Using Actionscript

查看:146
本文介绍了更改字符在字符串中使用ActionScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是相反的 String.charAt() ??

如果我有一个字符串:

VAR海峡:字符串=Hello World的;

如何更改的第五字符,例如,从一个'到'_'?

How do I change the 5th character, for example, from a ' ' to an '_'?

我可以得到5个字符是这样的:

I can GET the 5th character like this:

变种C:字符串= Str.charAt(5);

但如何设置的第5个字符?

But how do I SET the 5th character?

在此先感谢。

推荐答案

有很多方法对皮肤这只猫。一,从我的头顶,将涉及使用String.substr:

There are many ways to skin this cat. One, off the top of my head, would involve String.substr:

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

或,与上述相同,但更广义:

or, the same as above, but more generalized:

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

这篇关于更改字符在字符串中使用ActionScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆