Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/mid
Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/mid
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras |
Filename: | Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/mid |
Read OK: | ✔ |
File size: | 011E bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* GCW 02/03/94 */ /* get substring of s at f-th character of length l */ mid(s,f,l) { local len,r,i; len = sizeof(s) - f; if (l > len) l = len; if (l <= 0) return ""; r = newstring(l); for (i = 0; --l >= 0; ) r[i++] = s[f++]; return r; }
00000000 2f 2a 20 47 43 57 20 30 32 2f 30 33 2f 39 34 20 |/* GCW 02/03/94 | 00000010 2a 2f 0a 2f 2a 20 67 65 74 20 73 75 62 73 74 72 |*/./* get substr| 00000020 69 6e 67 20 6f 66 20 73 20 61 74 20 66 2d 74 68 |ing of s at f-th| 00000030 20 63 68 61 72 61 63 74 65 72 20 6f 66 20 6c 65 | character of le| 00000040 6e 67 74 68 20 6c 20 2a 2f 0a 0a 6d 69 64 28 73 |ngth l */..mid(s| 00000050 2c 66 2c 6c 29 20 20 0a 7b 0a 20 20 20 20 6c 6f |,f,l) .{. lo| 00000060 63 61 6c 20 6c 65 6e 2c 72 2c 69 3b 0a 20 20 20 |cal len,r,i;. | 00000070 20 6c 65 6e 20 3d 20 73 69 7a 65 6f 66 28 73 29 | len = sizeof(s)| 00000080 20 2d 20 66 3b 0a 20 20 20 20 69 66 20 28 6c 20 | - f;. if (l | 00000090 3e 20 6c 65 6e 29 0a 20 20 20 20 20 20 20 20 6c |> len). l| 000000a0 20 3d 20 6c 65 6e 3b 0a 20 20 20 20 69 66 20 28 | = len;. if (| 000000b0 6c 20 3c 3d 20 30 29 20 72 65 74 75 72 6e 20 22 |l <= 0) return "| 000000c0 22 3b 0a 20 20 20 20 72 20 3d 20 6e 65 77 73 74 |";. r = newst| 000000d0 72 69 6e 67 28 6c 29 3b 0a 20 20 20 20 66 6f 72 |ring(l);. for| 000000e0 20 28 69 20 3d 20 30 3b 20 2d 2d 6c 20 3e 3d 20 | (i = 0; --l >= | 000000f0 30 3b 20 29 0a 20 20 20 20 20 20 20 20 72 5b 69 |0; ). r[i| 00000100 2b 2b 5d 20 3d 20 73 5b 66 2b 2b 5d 3b 0a 20 20 |++] = s[f++];. | 00000110 20 20 72 65 74 75 72 6e 20 72 3b 0a 7d 0a | return r;.}.| 0000011e