Uli
Uli

Reputation: 2693

AS3 - Split string

How to allow splitting only if _x are the latest 2 characters in the string?

Example: hello-world_x.jpg should be splitted and hello_xtra_world.jpg not.

filename.text = imagename.text.split("_x").join("")

Thanks Uli

Upvotes: 1

Views: 953

Answers (2)

Joe
Joe

Reputation: 82594

You can use RegExp:

filename.text = imagename.text.split(/_x$/).join("")


Edit

This will work better:

imagename.text.replace(/(.+)_x(\.[a-z]+)/i, "$1$2");

Upvotes: 3

Rick van Mook
Rick van Mook

Reputation: 2065

I think it's better practice to use replace in combination with the RegExp @Joe-Tuskan suggested.

filename.text = imagename.text.replace(/_x$/, "");

Upvotes: 3

Related Questions