Ryan
Ryan

Reputation: 271

ActionScript 3: Deleting part of changing string

I understand how to delete part of a string from following this example

Deleting strings

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. What I'm trying to is remove all of the characters after the . so it should look like this.

str = 80

the string value is currently stored in str '80.30000'

Any suggestions ?

Upvotes: 0

Views: 51

Answers (2)

David Liam Clayton
David Liam Clayton

Reputation: 144

The best answer has probably already been given, but if you're using the number for anything mathematical, an alternativel might be to cast the String to a Float, Math.floor() the float (which should give you an integer), then cast it back to a String if required.

Upvotes: 0

user2655904
user2655904

Reputation:

Strings have functions like 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"
}

Documentation for substring(int,int)

Upvotes: 2

Related Questions