Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Split an integer to create ':' separated string

Hi Experts,

Party politics and partly the other dev doesn't want to change the data format he is sending I've been left with this problem.

I have an integer made up of 3 parts for example: 131110 I need to display this as 13:11:10.

How do I efficiently split this using asp.net VB.

This is further complicated by having to drop any leading zeros so:

90807 needs to show as 9:8:7 (the data width is 6, so assuming the left most digit to be 09)
081207 shows as 8:12:7
etc

Can anyone point me in the right direction please.

Andy
Avatar of sirbounty
sirbounty
Flag of United States of America image

Something like this - pulling from right to left...

myData = 90807

rightMost = right(myData,2)
middle=RIGHT(LEFT(G11,LEN(G11)-2),2)
leftOver = =RIGHT(LEFT(G11,LEN(G11)-4),2)

newData = leftOver & ":" & middle & ":" & rightMost

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andy Green

ASKER

Thank you. I just pulled the LINQ code and it worked just as I need.

Andy