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

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

问题描述

String.charAt() 的反义词是什么??

如果我有一个字符串:

var Str:String="Hello World";

如何将第 5 个字符(例如,从"" 更改为_")?

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

我可以像这样获取第 5 个字符:

I can GET the 5th character like this:

var C:String=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天全站免登陆