[REBOL] Interleaving strings -How? Re:
From: al:bri:xtra at: 24-Sep-2000 11:47
> After having read the docs I have not quite figured out how to accomplish
the interleaving of strings.
> The short and the long of what I want to do is take latitude and longitude
coordinate pairs and interleave them with each other.
Try this QaD:
[
Rebol []
Pad: function [Degree [decimal!]] [String] [
Degree: abs Degree
String: to string! Degree
if Degree < 10 [String: join "0" String]
if Degree < 100 [String: join "0" String]
if not found? find String "." [append String "."]
String
]
Interleave: function [Latitude [decimal!] Longitude [decimal!]] [String] [
Latitude: Pad Latitude
Longitude: Pad Longitude
while [< length? Latitude length? Longitude] [
Latitude: join Latitude "0"
]
while [> length? Latitude length? Longitude] [
Longitude: join Longitude "0"
]
String: rejoin [
copy/part Latitude 3
copy/part Longitude 3
]
for Index 5 length? Latitude 2 [
append String copy/part at Latitude Index 2
append String copy/part at Longitude Index 2
]
String
]
Latitude: 043.6732452849
Longitude: 142.8321724625
print Interleave Latitude Longitude
]
>> do %LatLong.r
04314267833221457228464925
Such a nice explanation deserved a nice reward.
Andrew Martin
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/