hi i have this variable which looks like this ؛‎ ‎002005 And i want to split it into two halfs three each . What i want to do is to put the first 3 numbers in a new variable and to remove its starting zero padding to get only 2 and the second half also to get just 5
Thank you very much
any help woild be apreciated

Recommended Answers

I'm no expert at js - here's a start. Doubtless, there will be a better way to do it...

var str = '002005';
var bits = str.match(/.{1,3}/g);
alert(parseInt(bits[0]));
alert(parseInt(bits[1]));
Jump to Post

All 5 Replies

Member Avatar

I'm no expert at js - here's a start. Doubtless, there will be a better way to do it...

var str = '002005';
var bits = str.match(/.{1,3}/g);
alert(parseInt(bits[0]));
alert(parseInt(bits[1]));

thank you it's a good kick off

Member Avatar

Can't believe I got a -1 for that! :)

sorry man i meant to upvote you but i doing it from my mobile and i dont know to get it back sorry agai

Member Avatar

Ha ha, no worries. I seem to get -1 all over the place for pretty harmless posts, thought somebody had a grudge against me. Anyway, glad you got it sorted. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.