How to extract part of a string?

Hi, I’m trying to get a number out of a string that is inside brackets like:

object[1]
object[23]

I only want to have the number. I haven’t manipulated strings a lot before and I’m not sure if there are any funtions for this. Any help would be great, thanks!

I have tried this:

var name : String = 'object[1]';
var foundS1: int = name.IndexOf("[");
name = name.Remove(0, foundS1);
name.Replace('[', '');
name.Replace(']', '');

but the result is ‘[1]’ and not ‘1’

1 Answer

1

Found the solution in MSDN Library:

var name : String = 'object[1]';
var foundS1: int = name.IndexOf("[");
name = name.Substring(foundS1+1, name.Length - 2 - foundS1);