[SOLVED] I need to split up a line into an array. Got all but the last part - any help?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

[SOLVED] I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Fri Sep 25, 2020 6:45 pm

I have this code:

Code: Select all

replace space with ";" in newLine
               
               set itemdel to ";"
               
               put trueword 1 of newLine into OPSIDTime
               
               replace ";" with tab in OPSIDTime
               
               set itemdel to tab
               
               put trueword 1 of OPSIDTime into OPSID
               put trueword 2 of OPSIDTime into OPSTime
               
               set itemdel to ";"
               
               put trueword 2 of newLine into OPSSource
               put trueword 3 of newLine into OPSDestination
               put trueword 4 of newLine into OPSProtocol
               put trueword 5 of newLine into OPSLength
               put anything after trueword 6 of newLine into OPSInfo
               
               put "ID: " & OPSID & cr & "Time: " & OPSTime & cr & "Source: " & OPSSource & cr & "Destination: " & OPSDestination & cr & "Protocol: " & OPSProtocol & cr & "Length: " & OPSLength & cr & "Info: " & OPSInfo into field "fldRD"
               
All works except the last (put anything after trueword 6...)

I know that's wrong, but I do not know how to get the rest of the line in the last array variable (OPSInfo).

How do I do this?

Thanks.

Mike
Last edited by karmacomposer on Tue Sep 29, 2020 9:21 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7321
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by dunbarx » Sat Sep 26, 2020 2:23 am

Hi.

Hard to know what is going on without much more context.

What is in "anything", or was that some catchall experimental term? What is in "newLine"?

Why are you setting the itemDel so often, when you never actually do anything with items?

Craig

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Sat Sep 26, 2020 2:28 pm

Craig,

There are reasons I set the itemDelim so much.

I have chunks of data I am turning into arrays and I need to parse the 2nd line into it's requisite parts. I have all but the last.

I'll upload a data fragment in a bit.

Mike

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7321
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by dunbarx » Sat Sep 26, 2020 3:24 pm

Hi.

Data would be nice, but if your script is internally incomplete I am not sure we can answer effectively.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5792
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by jacque » Sat Sep 26, 2020 6:25 pm

Seeing a sample would help. Maybe this would work though:

Code: Select all

put trueword 7 to - 1 of newLine into OPSInfo
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3461
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by bn » Sat Sep 26, 2020 6:25 pm

All works except the last (put anything after trueword 6...)
would this help?

Code: Select all

put trueWord 7 to -1 of newLine into OPSInfo
Kind regards
Bernd

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Sun Sep 27, 2020 3:50 am

I can test it tomorrow. I am in a push to import 10 million data records. At 6.9 million right now. Took 19 hours.

Mike

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8322
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by FourthWorld » Sun Sep 27, 2020 6:58 am

karmacomposer wrote:
Sun Sep 27, 2020 3:50 am
I can test it tomorrow. I am in a push to import 10 million data records. At 6.9 million right now. Took 19 hours.
What sort of DB is the data going into?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Tue Sep 29, 2020 1:42 am

FourthWorld wrote:
Sun Sep 27, 2020 6:58 am
karmacomposer wrote:
Sun Sep 27, 2020 3:50 am
I can test it tomorrow. I am in a push to import 10 million data records. At 6.9 million right now. Took 19 hours.
What sort of DB is the data going into?
Our own. Not a database. Not a blockchain. A bit of both.

Finished 10 million records in 2 days. Phew!

Mike

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Tue Sep 29, 2020 3:00 am

bn wrote:
Sat Sep 26, 2020 6:25 pm
All works except the last (put anything after trueword 6...)
would this help?

Code: Select all

put trueWord 7 to -1 of newLine into OPSInfo
Kind regards
Bernd
Thank you. That worked.

Let me ask you: I have two other sections to parse. I will never know their exact length, but I need to parse and show them in separate areas of my form. Here is an example of one entire data record:

Code: Select all

+-+-+-+-+-+-+-+-+-+ No.     Time           Source                Destination           Protocol Length Info
      1 0.000000       192.168.26.252        192.168.202.52        TCP      1438   2364 → 80 [ACK] Seq=1 Ack=1 Win=63948 Len=1380

Frame 1: 1438 bytes on wire (11504 bits), 1438 bytes captured (11504 bits)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 12, 2011 14:27:24.118438000 Eastern Standard Time
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1299958044.118438000 seconds
    [Time delta from previous captured frame: 0.000000000 seconds]
    [Time delta from previous displayed frame: 0.000000000 seconds]
    [Time since reference or first frame: 0.000000000 seconds]
    Frame Number: 1
    Frame Length: 1438 bytes (11504 bits)
    Capture Length: 1438 bytes (11504 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:vlan:ethertype:ip:tcp]
    [Coloring Rule Name: HTTP]
    [Coloring Rule String: http || tcp.port == 80 || http2]
Ethernet II, Src: Cisco_9d:f2:ce (00:16:47:9d:f2:ce), Dst: VMware_e7:94:14 (00:0c:29:e7:94:14)
    Destination: VMware_e7:94:14 (00:0c:29:e7:94:14)
        Address: VMware_e7:94:14 (00:0c:29:e7:94:14)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: Cisco_9d:f2:ce (00:16:47:9d:f2:ce)
        Address: Cisco_9d:f2:ce (00:16:47:9d:f2:ce)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: 802.1Q Virtual LAN (0x8100)
802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 120
    000. .... .... .... = Priority: Best Effort (default) (0)
    ...0 .... .... .... = DEI: Ineligible
    .... 0000 0111 1000 = ID: 120
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.26.252, Dst: 192.168.202.52
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
        0000 00.. = Differentiated Services Codepoint: Default (0)
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    Total Length: 1420
    Identification: 0x7f4d (32589)
    Flags: 0x4000, Don't fragment
        0... .... .... .... = Reserved bit: Not set
        .1.. .... .... .... = Don't fragment: Set
        ..0. .... .... .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 127
    Protocol: TCP (6)
    Header checksum: 0x109d [validation disabled]
    [Header checksum status: Unverified]
    Source: 192.168.26.252
    Destination: 192.168.202.52
Transmission Control Protocol, Src Port: 2364, Dst Port: 80, Seq: 1, Ack: 1, Len: 1380
    Source Port: 2364
    Destination Port: 80
    [Stream index: 0]
    [TCP Segment Len: 1380]
    Sequence number: 1    (relative sequence number)
    Sequence number (raw): 789663477
    [Next sequence number: 1381    (relative sequence number)]
    Acknowledgment number: 1    (relative ack number)
    Acknowledgment number (raw): 1215947197
    0101 .... = Header Length: 20 bytes (5)
    Flags: 0x010 (ACK)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...1 .... = Acknowledgment: Set
        .... .... 0... = Push: Not set
        .... .... .0.. = Reset: Not set
        .... .... ..0. = Syn: Not set
        .... .... ...0 = Fin: Not set
        [TCP Flags: ·······A····]
    Window size value: 63948
    [Calculated window size: 63948]
    [Window size scaling factor: -1 (unknown)]
    Checksum: 0x0d62 [unverified]
    [Checksum Status: Unverified]
    Urgent pointer: 0
    [SEQ/ACK analysis]
        [Bytes in flight: 1380]
        [Bytes sent since last PSH flag: 1380]
    [Timestamps]
        [Time since first frame in this TCP stream: 0.000000000 seconds]
        [Time since previous frame in this TCP stream: 0.000000000 seconds]
    TCP payload (1380 bytes)

0000  00 0c 29 e7 94 14 00 16 47 9d f2 ce 81 00 00 78   ..).....G......x
0010  08 00 45 00 05 8c 7f 4d 40 00 7f 06 10 9d c0 a8   ..E....M@.......
0020  1a fc c0 a8 ca 34 09 3c 00 50 2f 11 4e f5 48 79   .....4.<.P/.N.Hy
0030  e1 bd 50 10 f9 cc 0d 62 00 00 b5 a6 9e ce 5f 02   ..P....b......_.
0040  46 bb 3e b0 7f 29 77 2e 54 05 06 df 4f 25 f9 bb   F.>..)w.T...O%..
0050  86 68 f6 5a cf 34 b3 9e e0 74 f1 28 3f 25 70 7e   .h.Z.4...t.(?%p~
0060  d3 68 3e da 45 f0 aa 00 26 e5 e0 2f ee dd 12 7b   .h>.E...&../...{
0070  f6 c6 ef 23 c6 af bf 01 d6 39 50 cd 05 29 eb 52   ...#.....9P..).R
0080  93 3f a4 3a 56 f9 01 9e 03 82 8a 4a fe c5 80 d2   .?.:V......J....
0090  c9 bc ad 56 2b 4a a7 b9 e0 26 8c 87 0d 87 5f 1c   ...V+J...&...._.
00a0  14 5c ee 26 df b5 c7 94 6d b7 87 9e 18 83 9a fc   .\.&....m.......
00b0  65 26 0d 51 66 44 b7 69 b0 1e f2 f6 92 e3 51 7a   e&.QfD.i......Qz
00c0  24 5d 70 75 5b c6 74 08 bf 67 64 27 ca e1 27 45   $]pu[.t..gd'..'E
00d0  72 b7 68 20 0d 5b f3 dd 18 6e c7 17 c3 a4 ec db   r.h .[...n......
00e0  6f 27 46 ca e0 19 fe d1 33 c8 aa 99 78 ae a0 a9   o'F.....3...x...
00f0  c2 27 58 d5 88 2c 3e f5 e4 db b2 ca 5c ad 8f b7   .'X..,>.....\...
0100  fe 80 0d 5b 36 d9 d7 e1 7d 6a 17 31 6d 76 b0 d9   ...[6...}j.1mv..
0110  88 82 fb 32 d8 04 da 7c 9a 86 8a fa 2d fa 49 44   ...2...|....-.ID
0120  fa 77 5c ba 2e c8 e3 99 3c e7 13 60 32 38 e7 0d   .w\.....<..`28..
0130  dc ab a6 18 89 09 1c e4 77 c1 c7 2b 87 77 e6 57   ........w..+.w.W
0140  a8 60 27 b8 c9 d3 bb 5e f9 e1 1c fc 04 33 74 12   .`'....^.....3t.
0150  52 f6 8e 69 47 c8 41 e0 65 22 7b 7e 84 a3 da 0c   R..iG.A.e"{~....
0160  dc d5 89 1b bc 65 7d f4 1f 8f d4 42 31 60 8a 66   .....e}....B1`.f
0170  44 ac 11 bb e3 36 f7 61 83 4d fe cb 9c 99 00 f1   D....6.a.M......
0180  53 63 4a 3b c6 89 81 4e ab 19 c6 20 58 00 dc 73   ScJ;...N... X..s
0190  a1 e4 61 de 97 e9 d9 a1 66 0a ba 7d 3e f2 d1 69   ..a.....f..}>..i
01a0  f0 2a b8 c0 ba dd 6b 0c 41 df 38 2c e3 d9 2a e1   .*....k.A.8,..*.
01b0  06 fb 24 45 8d 0c dd 55 e3 0e cc d5 ad c3 91 5f   ..$E...U......._
01c0  18 16 e5 d2 19 88 af d5 69 58 20 3a ff de 8b 66   ........iX :...f
01d0  8b 1c 11 a7 76 8b 30 bf 2d ab f2 6f dd 00 64 d7   ....v.0.-..o..d.
01e0  36 f2 31 43 99 7d ba 30 13 71 39 11 0c 6a f1 c8   6.1C.}.0.q9..j..
01f0  d1 45 ff 4b 9d 58 5e 97 f3 57 21 35 2b d9 5d b5   .E.K.X^..W!5+.].
0200  79 f8 14 52 b3 a0 ea 85 51 2c 80 fa d0 39 35 33   y..R....Q,...953
0210  1a 6e 58 83 0b f6 62 f3 23 30 2a 2f fd c4 01 04   .nX...b.#0*/....
0220  57 3e ce 88 a7 47 4f f6 01 37 2f 78 f3 d9 38 df   W>...GO..7/x..8.
0230  36 f2 e5 4c 59 31 e1 a8 c0 47 a6 67 b4 33 ff fa   6..LY1...G.g.3..
0240  61 e4 4d 1d 6d eb a0 ec e3 98 21 8e c3 e5 ac 63   a.M.m.....!....c
0250  b4 13 17 63 fd 93 7c 2a 13 b7 40 98 37 57 32 82   ...c..|*..@.7W2.
0260  dc 4d 92 a1 bd 8e f4 9e e5 a6 5f ca f8 e3 a3 f5   .M........_.....
0270  8b d2 6b 5a 26 e2 f3 04 c3 39 79 30 58 91 6a 40   ..kZ&....9y0X.j@
0280  c3 d7 13 54 51 2e 06 98 69 f8 b9 62 8b 47 d2 69   ...TQ...i..b.G.i
0290  3c 61 a0 d3 59 8f ff ef 49 52 82 e2 e8 57 7b bf   <a..Y...IR...W{.
02a0  34 74 b4 a4 34 94 ae 90 c7 50 a2 b6 19 3a e9 81   4t..4....P...:..
02b0  c0 e3 d4 44 ec 45 d7 19 37 74 2f c7 62 6f cb 27   ...D.E..7t/.bo.'
02c0  82 a7 15 a0 17 e8 d6 a3 ce 5e ca 5a 4c 2d b4 21   .........^.ZL-.!
02d0  16 39 09 32 d7 97 4c b4 4c de 35 52 66 48 f0 be   .9.2..L.L.5RfH..
02e0  cd a7 c8 dd fd 36 69 a6 3a 8a 50 7c 73 8e c4 83   .....6i.:.P|s...
02f0  c1 cc b0 b3 c8 01 57 f4 0b 19 84 07 b8 ff d5 f5   ......W.........
0300  91 d7 5e 98 54 86 0b b1 33 26 19 55 9e 6b 7d f6   ..^.T...3&.U.k}.
0310  a7 c1 c0 2e aa 92 f3 36 9b 7c df f3 f0 ef 37 7c   .......6.|....7|
0320  33 42 04 f5 26 fb 57 50 23 0a 35 1f 2b 61 43 91   3B..&.WP#.5.+aC.
0330  ea fb 04 5d d8 25 1a e9 52 fc 16 98 94 80 b9 3c   ...].%..R......<
0340  69 33 de 39 e5 0d 6b e1 a8 fa d5 90 78 0a dd 81   i3.9..k.....x...
0350  8c 7a 52 a0 0d ad ff 8a a5 dc b4 61 b7 b3 8e cc   .zR........a....
0360  68 9b d6 c1 ba 35 0a 86 92 98 da 83 0e a4 76 cf   h....5........v.
0370  47 7a 71 bf db 8b e2 0b 3b 61 26 01 ad 5d a8 a8   Gzq.....;a&..]..
0380  29 3f 4e 07 d9 0b 78 12 9e 3a e5 b9 ba a6 59 fa   )?N...x..:....Y.
0390  89 0f e2 e0 1d f9 bc 05 89 17 a8 4f 30 f8 ce 50   ...........O0..P
03a0  b9 77 6c bc c7 b9 df d5 63 3a c8 58 49 00 98 bf   .wl.....c:.XI...
03b0  df d8 ce 8c 61 b8 6f 4a 88 68 c7 d6 8d d2 72 ed   ....a.oJ.h....r.
03c0  b7 38 5c ad 24 9b 70 22 ce d8 4c 27 4f 4c 62 9f   .8\.$.p"..L'OLb.
03d0  bb eb 75 2b b1 29 07 8b f8 99 86 c6 8a 30 7e 99   ..u+.).......0~.
03e0  33 e2 74 2d 81 45 58 b6 2a 7d 3a 6d c0 36 29 da   3.t-.EX.*}:m.6).
03f0  87 fd a0 4b a9 a5 1b 13 9d 67 5d 02 53 b8 33 72   ...K.....g].S.3r
0400  33 f8 92 1e 48 7b 7c d0 ee c9 65 87 73 cd 45 cf   3...H{|...e.s.E.
0410  4d 93 e8 c4 42 9f 1d d7 07 8a 96 8d df ec 8b c5   M...B...........
0420  cf ae d5 56 07 1f f6 48 40 79 71 09 fd f1 db 4d   ...V...H@yq....M
0430  fa cb e1 62 49 ab 0f c5 d8 de 81 03 8e 2d 55 72   ...bI........-Ur
0440  7e e6 db 4a 5c 08 f4 a2 0a b9 b4 e5 be 73 54 8f   ~..J\........sT.
0450  48 e4 d0 42 5a fc 8b 7d 69 b5 13 c0 1f 18 56 6a   H..BZ..}i.....Vj
0460  5d a2 17 b1 7a 97 e2 eb fd 01 9f f1 0e 7a 38 f6   ]...z........z8.
0470  7e a0 af 36 cc 44 ae 7f 08 0e df e1 5d c1 3e a5   ~..6.D......].>.
0480  0f 73 20 13 10 61 7c 54 e5 83 85 6d 56 77 2c 92   .s ..a|T...mVw,.
0490  c8 65 ee 37 83 48 16 a2 52 c9 95 af 85 b7 90 38   .e.7.H..R......8
04a0  a0 3e d0 92 ba 53 b3 bc 83 e7 3e e6 6c ac 0f 2e   .>...S....>.l...
04b0  4a 04 3d 54 cb d9 87 6b d9 68 ee e7 f9 32 b0 05   J.=T...k.h...2..
04c0  30 b3 57 23 89 2f 37 e5 2e b4 21 e3 13 13 1f e1   0.W#./7...!.....
04d0  ca 81 49 41 da 6a 3a 57 8f 96 c7 b1 e6 e7 cd ba   ..IA.j:W........
04e0  72 d0 32 22 71 f7 a5 89 92 00 82 c5 43 80 a1 66   r.2"q.......C..f
04f0  31 77 60 49 94 0e a1 6c af 46 ed 55 3d e3 b7 58   1w`I...l.F.U=..X
0500  31 75 b6 4f 45 1f 6a c6 35 6d 56 27 33 b8 0b 66   1u.OE.j.5mV'3..f
0510  4e fe ff e5 f4 b1 b5 5b de 1c c9 72 10 ca 57 79   N......[...r..Wy
0520  89 a5 31 49 76 ad 00 5a 55 02 f3 50 80 a1 d1 6a   ..1Iv..ZU..P...j
0530  9e fb 84 f5 c3 e9 c1 e7 3a 89 ed a1 2d 42 45 35   ........:...-BE5
0540  7c 6d 47 fd 1b 23 0e c6 13 7b ef 82 98 f9 89 60   |mG..#...{.....`
0550  4f 0a 08 74 be 82 f3 46 d9 c2 9f 17 2a 12 01 c5   O..t...F....*...
0560  3b 1b a4 8b fb a6 65 d5 a8 bc ec 5f 17 a1 00 76   ;.....e...._...v
0570  af 01 f3 27 6b e0 4b 5b ac 77 2d 4c 5d ef 78 f9   ...'k.K[.w-L].x.
0580  7e 92 ac 9c e1 8f d7 df d1 b5 78 39 ab 0d 38 13   ~.........x9..8.
0590  6f 83 2e fe 9c 22 90 19 ff b2 39 1b a8 0c         o...."....9...

+-+-+-+-+-+-+-+-+-+
I need to parse from Frame 1 to the end of that section as one variable to show in a text field (fldRD)

I then need to parse the hex data from beginning to end as well and display that in its own text field (fldHex). I think the Hex data will always start with 0000. That pattern at the bottom is what I created to act as a delimeter between records.

How would I go about doing this. Parsing text just confuses me once I get away from simple stuff.

Thank you for your help. It is greatly appreciated.

Mike

AxWald
Posts: 478
Joined: Thu Mar 06, 2014 2:57 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by AxWald » Tue Sep 29, 2020 8:40 am

Hi,
karmacomposer wrote:
Tue Sep 29, 2020 1:42 am
Our own. Not a database. Not a blockchain. A bit of both.
Finished 10 million records in 2 days. Phew!
If it'd take me 2 hours to import 10 mil records I'd finally donate my mac Plus with its FileMaker 1.0 to the museum, and migrate to mySQL (or better) in a modern data center ;-)))

Sry, couldn't resist.
karmacomposer wrote:
Tue Sep 29, 2020 3:00 am
I need to parse from Frame 1 to the end of that section as one variable to show in a text field (fldRD)
I then need to parse the hex data from beginning to end as well and display that in its own text field (fldHex).
Try this:

Code: Select all

on mouseUp
   put fld "data_fld" into myData  --  your example data
   
   put CR & "Frame 1: " into myStart
   put CR & CR & "0000  " into myEnd
   put inBeet_BL(myData,myStart,myEnd) into fld "frame1_fld"
   
   put CR & CR & "0000  " into myStart
   put CR & CR & "+-+-+-+-+-+-+-+-+-+" into myEnd
   put "0000  " & inBeet_BL(myData,myStart,myEnd) into fld "hex_fld"
end mouseUp

function inBeet_BL theString, theStart, theEnd, offNum
   /* inBeet_BL() is a very fast function - it extracts data between 2 search hits.
   
   # theString (String): The data you're searching in;
   
   # theStart, theEnd (String): what is before and after your desired text,
   . assumed that theEnd comes AFTER theStart, and that at least theEnd is not empty;
   . If you look for something at the beginning of theString, leave theStart empty -
   . in case of mode 2 (2-line return) you need to set offNum to 0 then.
   
   # OffNum (Int, optional): skip [offNum] chars at the beginning of theString;
   . 2 modes of action, depending on the value of offNum:
   
   - Mode 1: When offNum is empty, it just returns the found string, or empty;
   - Mode 2: When offNum <> empty, it returns a 2-line result:
   .        line 1 is the pos of the last char touched in theString (= last char found of theEnd) 
   .        and line 2 is the found string. Use line 1 as offNum for your next repeat!
   
   What negative values do for offNum is left as an exercise - it has a (strange) use too!
   axwald @ forums.livecode3.com, GPL v3, last mod 08/2020   */
   
   if (offNum is not empty) then
      if theStart is empty then 
         put 1 into theStart
      else
         put offset(theStart,theString,offNum) + len(theStart) + offNum into myStart
      end if
      if myStart is (len(theStart) + offNum) then return empty
      put offset(theEnd,theString,myStart) + (myStart)-1 into myEnd
      if myEnd is (myStart)-1 then return empty
      return myEnd & CR & char myStart to myEnd of theString
   else
      return char (offset(theStart,theString) + len(theStart)) to \
            (offset(theEnd,theString,(offset(theStart,theString) + len(theStart))) \
            + (offset(theStart,theString) + len(theStart))-1) \
            of theString
   end if
end inBeet_BL
Have fun!
Livecode programming until the cat hits the fan ...

stam
Posts: 196
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by stam » Tue Sep 29, 2020 10:11 am

karmacomposer wrote:
Tue Sep 29, 2020 3:00 am
I need to parse from Frame 1 to the end of that section as one variable to show in a text field (fldRD)
Hi Mike - there are many ways to do this - i would have done this by matching regex:

The regex query for Frame 1 onwards is (?msxi)Frame\s1:\s (.*?) \R\+-

Code: Select all

put "(?msxi)Frame\s1:\s (.*?) \R\+-" into tRegex
if matchText(textToParse, tRegex , R) then put R into fldRD
Note that R will not include the text "Frame 1: " at the start or (return & "+-") at the end, just what's between these. If you need those texts you can just add in manually (i.e. put "Field 1:" && R into fldRD)
karmacomposer wrote:
Tue Sep 29, 2020 3:00 am
I then need to parse the hex data from beginning to end as well and display that in its own text field (fldHex). I think the Hex data will always start with 0000. That pattern at the bottom is what I created to act as a delimeter between records.
similarly for this, regex query would be (?msxi)\R0000\s(.*?) \R\+-
note that this will capture only what's between (return & "0000 ") and (return & "+-"), you'll have to add the "0000 " again at the end.

Code: Select all

put "(?msxi)\R0000(.*?) \R\+-" into tRegex
if matchText(textToParse, tRegex , R) then put "0000" && R into fldHex
I've tested the regex in RegExRX and it works - but haven't tested this specifically in LC - should work tho, i use this kind of thing a lot. Where i have multiple regexes to perform store these in a custom stack property as an array so i can just refer to them as [regexes][frame1] and [regexes][hex] for example....

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 795
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by Thierry » Tue Sep 29, 2020 11:09 am

stam wrote: ....
i would have done this by matching regex:
Hi stam,

Nice to see another regex-livecoder :)

Here is my solution made in less than 3 minutes:

Code: Select all

on regexSolution
   local rex = "(?ms)^Frame 1: (.*?)\n\n(0000 .*?)(?=\n\n\+\-)"
   
   if matchText( fld "Text_IN", rex, frame1Data, hexData) then
      put frame1Data into fld "frame1_fld"
      put hexData into fld "hex_fld"
   else
      put "No match!" into fld "frame1_fld"
   end if
end regexSolution
and got the same results as Axwald solution.

Happy coding,

Thierry
Regex LiveCode sunnYrex
https://sunny-tdz.com

stam
Posts: 196
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by stam » Tue Sep 29, 2020 6:03 pm

Thanks Thierry, that’s much more elegant!

I’m very much a newbie at regex and always find your examples extremely helpful and informative!

karmacomposer
Posts: 355
Joined: Wed Apr 27, 2011 2:12 pm

Re: I need to split up a line into an array. Got all but the last part - any help?

Post by karmacomposer » Tue Sep 29, 2020 9:21 pm

AxWald wrote:
Tue Sep 29, 2020 8:40 am
Hi,
karmacomposer wrote:
Tue Sep 29, 2020 1:42 am
Our own. Not a database. Not a blockchain. A bit of both.
Finished 10 million records in 2 days. Phew!
If it'd take me 2 hours to import 10 mil records I'd finally donate my mac Plus with its FileMaker 1.0 to the museum, and migrate to mySQL (or better) in a modern data center ;-)))

Sry, couldn't resist.
karmacomposer wrote:
Tue Sep 29, 2020 3:00 am
I need to parse from Frame 1 to the end of that section as one variable to show in a text field (fldRD)
I then need to parse the hex data from beginning to end as well and display that in its own text field (fldHex).
Try this:

Code: Select all

on mouseUp
   put fld "data_fld" into myData  --  your example data
   
   put CR & "Frame 1: " into myStart
   put CR & CR & "0000  " into myEnd
   put inBeet_BL(myData,myStart,myEnd) into fld "frame1_fld"
   
   put CR & CR & "0000  " into myStart
   put CR & CR & "+-+-+-+-+-+-+-+-+-+" into myEnd
   put "0000  " & inBeet_BL(myData,myStart,myEnd) into fld "hex_fld"
end mouseUp

function inBeet_BL theString, theStart, theEnd, offNum
   /* inBeet_BL() is a very fast function - it extracts data between 2 search hits.
   
   # theString (String): The data you're searching in;
   
   # theStart, theEnd (String): what is before and after your desired text,
   . assumed that theEnd comes AFTER theStart, and that at least theEnd is not empty;
   . If you look for something at the beginning of theString, leave theStart empty -
   . in case of mode 2 (2-line return) you need to set offNum to 0 then.
   
   # OffNum (Int, optional): skip [offNum] chars at the beginning of theString;
   . 2 modes of action, depending on the value of offNum:
   
   - Mode 1: When offNum is empty, it just returns the found string, or empty;
   - Mode 2: When offNum <> empty, it returns a 2-line result:
   .        line 1 is the pos of the last char touched in theString (= last char found of theEnd) 
   .        and line 2 is the found string. Use line 1 as offNum for your next repeat!
   
   What negative values do for offNum is left as an exercise - it has a (strange) use too!
   axwald @ forums.livecode3.com, GPL v3, last mod 08/2020   */
   
   if (offNum is not empty) then
      if theStart is empty then 
         put 1 into theStart
      else
         put offset(theStart,theString,offNum) + len(theStart) + offNum into myStart
      end if
      if myStart is (len(theStart) + offNum) then return empty
      put offset(theEnd,theString,myStart) + (myStart)-1 into myEnd
      if myEnd is (myStart)-1 then return empty
      return myEnd & CR & char myStart to myEnd of theString
   else
      return char (offset(theStart,theString) + len(theStart)) to \
            (offset(theEnd,theString,(offset(theStart,theString) + len(theStart))) \
            + (offset(theStart,theString) + len(theStart))-1) \
            of theString
   end if
end inBeet_BL
Have fun!
Thank you sir. Your idea worked for the 1st part. The 2nd part, it turns out, did not have the pattern, so there was nothing to end with. However, I was able to figure out how to delete the data and be left with the hex data and put that into a separate variable. Works perfectly.

I tried the regex examples, but they did not work for me at all.

Thanks again.

Mike

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”