views:

53

answers:

2

Hi, I have string like fullData1 upto fullData10 in this i need to separate out the integers and text part. how do I do it using javascript.

+2  A: 

Split your string into an array by integer:

myArray = datastring.split(/[0-9]+/)

Then the first element of myArray will be something like fullData and the second will be some numbers such as 1 or 10.

If your string was fullData10foo then you would have an array {'fullData',10,'foo'}

Aiden Bell
this will remove the integer and leave 2 components, the *fullData* string and an empty string. Use a positive lookahead instead, e.g. `.split(/(?=\d+)/)`. **edit** the additional information you provided makes this comment a little less accurate but the point remains - split will remove the string you split on.
Andy E
+1  A: 

If the length of the character part is constant, you can very well remove them using a substring method.

Kangkan