Mercy
Mercy

Reputation: 1860

issues to split the string in flex?

hi am trying to split the string in flex,but i can't to separate correctly

private var image_path:String = "http://pvm4.yyy.in/sample-31/demo/img0.jpg";

I want to split the number 0

so am trying this code

image_path.substring(image_path.lastIndexOf("/img"));

but am getting img0.jpg i need 0 only how to split this?

Upvotes: 0

Views: 169

Answers (2)

Jerome Cance
Jerome Cance

Reputation: 8183

You can do it the same way but by adding the length of your parameter :

(the syntax could not be good as I don't know flex)

image_path.substring(image_path.lastIndexOf("/img") + "/img".length);

But you sould use the following regex to get the number :

.*/demo/img([0-9]+)\.jpg

then use capturing group to get the number ;)

Upvotes: 0

Eduardo
Eduardo

Reputation: 8402

image_path.substring(image_path.lastIndexOf("/img")+4, image_path.length-4);

Upvotes: 3

Related Questions