- Home /
Question by
thaiscorpion · Nov 27, 2013 at 03:06 PM ·
javascriptstringextract
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'
Comment
Best Answer
Answer by thaiscorpion · Nov 27, 2013 at 03:39 PM
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);
Your answer
Follow this Question
Related Questions
Creating multidimensional string array 1 Answer
Problem with looping concatenation with custom class 1 Answer
Converting a .CSV string array to a float array 1 Answer
Best way to emulate Swift String Interpolation in UnityScript? 1 Answer
Why do I have to call ToString() when fetching a String from another script? 2 Answers