Message Boards Message Boards

0
|
4521 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Replacement of variable amount of marks in sublists

Posted 11 years ago
Hi Everyone
I 'm trying to figure out  the following problem :
I got a list :
 {{7,95"........... 2000 ........... 17:00:07"}, {11,
   "00 ........... 2000 ........... 17:00:16"}, {14,
   "05 ............ 180 ............ 17:00:40"}, {13,
   "97 .......... 700 ............... 10:01:41"}, {2,
   "98 ............. 379 ............ 09:39:36"}, {5,
   "03 .......... 200 .............. 09:13:11"}, {7,
   "12 ............ 250 .............. 09:15:44"}, {10,
   "30 ............. 921 ............ 16:12:00"}, {12,
   "45 .......... 2000 ............... 16:38:52"},....... {8,
  "00 ............. 265 ...........12:29:12"}}
And I'd like to get the final results in this way :{7.95,2000,17:00:07}, {11.00,2000,17:00:16}, {14.05,180,17:00:40},....
The most difficult for me is getting rid of  dots and putting separating commas in these places because the amount of dots  are  different within each sublists.

Thanks for suggestions .
POSTED BY: Artur Kotarski
3 Replies
Posted 11 years ago
Here is a more useable format, each of the numbers except the date format ones are converted to numbers, its also in a table format for better virewing.  There are a number of assumptions. No1, the number at the begining of each line will always be in 2 digit decimal form, i.e. nn..n,mm.  No2, the time format at the end of each line will always be at the end and nothing else will be after it.

 s1 = {{7, 95 "........... 2000 ........... 17:00:07"}, {11,
    "00 ........... 2000 ........... 17:00:16"}, {14,
    "05 ............ 180 ............ 17:00:40"}, {13,
    "97 .......... 700 ............... 10:01:41"}, {2,
    "98 ............. 379 ............ 09:39:36"}, {5,
    "03 .......... 200 .............. 09:13:11"}, {7,
    "12 ............ 250 .............. 09:15:44"}, {10,
    "30 ............. 921 ............ 16:12:00"}, {12,
    "45 .......... 2000 ............... 16:38:52"}, {8,
   "00 ............. 265 ...........12:29:12"}};
list = {}; Do[ls = StringLength[ToString[s1[[q]]]];
a = StringTake[ToString[s1[[q]]], {ls - 8, ls - 1}];
AppendTo[list, {Partition[StringCases[ToString[s1[[q]]], RegularExpression["\\w+"], 3], 3],
   a}], {q, 1, Length[s1]}]; list = Partition[Flatten[list], 4]; list1 = {}; Do[AppendTo[list1, {N[(FromDigits[list[[q, 1]]]*100 +
       FromDigits[list[[q, 2]]])/100], FromDigits[list[[q, 3]]],
   list[[q, 4]]}], {q, 1, Length[list]}];
Print[TableForm[list1]];
Print[
Column[list1]];
PrependTo[list1, {"No1", "No2", "TIME"}];
Print[Grid[list1, Background -> {None, {1 -> Yellow}},
Alignment -> Left, Frame -> All, Spacings -> {1, 1}]]
 7.95    2000    17:00:07
 
 11.    2000    17:00:16
 14.05    180    17:00:40
 13.97    700    10:01:41
 2.98    379    09:39:36
 5.03    200    09:13:11
 7.12    250    09:15:44
 10.3    921    16:12:00
12.45    2000    16:38:52
8.    265    12:29:12

{7.95,2000,17:00:07}
{11.,2000,17:00:16}
{14.05,180,17:00:40}
{13.97,700,10:01:41}
{2.98,379,09:39:36}
{5.03,200,09:13:11}
{7.12,250,09:15:44}
{10.3,921,16:12:00}
{12.45,2000,16:38:52}
{8.,265,12:29:12}

No1    No2    TIME
7.95    2000    17:00:07
11.    2000    17:00:16
14.05    180    17:00:40
13.97    700    10:01:41
2.98    379    09:39:36
5.03    200    09:13:11
7.12    250    09:15:44
10.3    921    16:12:00
12.45    2000    16:38:52
8.    265    12:29:12

Paul.
POSTED BY: Paul Cleary
Posted 11 years ago
Thank You for your reply
POSTED BY: Artur Kotarski
Posted 11 years ago
This is one way of looking at it, though you don't say if you want to be able to use the data again, or just look at it, however see what you think to this, I'm sure there are more elegant ways to do it too.
 s1 = {{7, 95 "........... 2000 ........... 17:00:07"}, {11,
 
     "00 ........... 2000 ........... 17:00:16"}, {14,
 
     "05 ............ 180 ............ 17:00:40"}, {13,
 
     "97 .......... 700 ............... 10:01:41"}, {2,
 
     "98 ............. 379 ............ 09:39:36"}, {5,

    "03 .......... 200 .............. 09:13:11"}, {7,

    "12 ............ 250 .............. 09:15:44"}, {10,

    "30 ............. 921 ............ 16:12:00"}, {12,

    "45 .......... 2000 ............... 16:38:52"}, {8,

    "00 ............. 265 ...........12:29:12"}};

list = {}; Do[AppendTo[list,Partition[StringCases[ToString[s1[[q]]], RegularExpression["\\w+"]],6]], {q, 1, Length[s1]}]; list = Flatten[list, 1]; Do[Print[list[[q, 1]], ".", list[[q, 2]], ",", list[[q, 3]], ",",list[[q, 4]], ":", list[[q, 5]], ":", list[[q, 6]]], {q,1,Length[list]}]

Paul.
POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract