ActionScript 3:删除部分变化的字符串

ActionScript 3: Deleting part of changing string

我从这个例子中了解了如何删除字符串的一部分

Deleting strings

但问题是我的字符串在不断变化。

str 返回的值为:80.30000 这取决于所选的值。我想要的是删除 . 之后的所有字符。所以它应该是这样的。

str = 80

字符串值当前存储在 str '80.30000'

有什么建议吗?

字符串有类似indexOf的函数。所以,为了得到字符的位置 . 你可以做下面的事情。

var str:String = "80.30000";
var indexOfPoint:int = str.indexOf(".");
if(indexOfPoint >= 0)
{
    //the string contains at least one . character
    str = str.substring(0, indexOfPoint);
    //now str holds only the String "80"
}

Documentation for substring(int,int)

可能已经给出了最佳答案,但是如果您将数字用于任何数学运算,另一种方法可能是将字符串转换为浮点数,Math.floor() 浮点数(应该给你一个整数),然后根据需要将其转换回字符串。