0

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 ?

Community
  • 1
  • 1
Ryan
  • 271
  • 2
  • 3
  • 7

2 Answers2

2

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)

  • Thanks great suggestion, i've been trying to implement and getting: 1061: Call to a possibly undefined method subString through a reference with static type String. – Ryan Apr 14 '16 at 11:57
  • Typo on my part, `substring` is all lowercase letters. –  Apr 14 '16 at 12:07
0

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.