[英]ActionScript 3: Deleting part of changing string
I understand how to delete part of a string from following this example 我了解如何从以下示例中删除字符串的一部分
But the problem is my string is constantly changing. 但是问题是我的弦在不断变化。
str is giving back a value of: 80.30000 this changes depending on the value selected. str返回的值是:80.30000,此值根据所选的值而变化。 What I'm trying to is remove all of the characters after the .
我要删除的是所有字符。 so it should look like this.
所以应该看起来像这样
str = 80 str = 80
the string value is currently stored in str '80.30000' 字符串值当前存储在str '80 .30000'中
Any suggestions ? 有什么建议么 ?
Strings have functions like indexOf . 字符串具有indexOf之类的功能。 So, in order to get the position of the character
.
因此,为了获得字符的位置
.
you can do the following. 您可以执行以下操作。
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"
}
最好的答案可能已经给出,但是如果您将数字用于任何数学运算,则替代方法可能是将String转换为Float,Math.floor()float(应该为您提供一个整数),然后如果需要,将其转换回字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.