Skip to content

Commit 47d5624

Browse files
authored
Merge pull request #569 from boriel/docs
doc: start of string.bas library documentation
2 parents 3ce166a + b9ef340 commit 47d5624

9 files changed

Lines changed: 445 additions & 4 deletions

File tree

docs/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#General
1+
#General
22
* [About](about.md)
33
<br />About the ZX BASIC SDK
44

@@ -31,9 +31,12 @@ Get the latest version of ZX BASIC from the [archive](archive.md).
3131
* [Data types](types.md)
3232
<br />Language data types: Instead of working always with Floating Point numbers (also available), there are also some integer types which are faster an take less memory.
3333

34-
* [Reserved words](identifier.md)
34+
* [Reserved words](identifier.md)
3535
<br />Comprehensive list (alphabetically ordered) of identifiers you shouldn't use as a ''variable name''. E.g. `FOR`, `PRINT`. If you want usage instructions on a statement, also look here.
3636

37+
* [Standard libraries](library/stdlib.md)
38+
<br />Standard libraries that comes bundled with the ZX Basic compiler.
39+
3740
## Tutorials
3841
* [Programming tutorials](tutorials.md)
3942
<br />A collection of third-party tutorials about development with ZX BASIC.

docs/library.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
This is a list of additions to the language that have been produced. They extend the functionality of the compiler by
66
effectively adding reserved words to the language. At their heart, they are all SUB or FUNCTION sets.
77

8+
For the standard library go to the [standard library](library/stdlib.md) page.
9+
10+
11+
---
12+
## Non-standard libraries
13+
14+
These ones might not be bundled yet with ZX Basic (mostly due to lack of time). If so, you have
15+
to copy the listing shown in this wiki and create the .bas file yourself, as explained in the following
16+
section.
17+
818
###How to Include a Library Function
919
You can either copy and paste the `SUB` or `FUNCTION` into your code, or, perhaps more easily,
1020
save the text as the recommended name (e.g. fSqrt.bas) and use `#include "fSqrt.bas"` at the start of the program.
@@ -84,7 +94,7 @@ Keep status updates scrolling in and sliding up without affecting the game windo
8494

8595
* [windowAttrScrollUP.bas](library/windowattrscrollup.md)
8696
<br /> Subroutine to character scroll the attributes of a window of screen - really a handy addendum utility
87-
for [windowScrollUP.bas](library/windowscrollup.md)
97+
for [windowScrollUP.bas](library/windowscrollup.md)
8898

8999
####Text Handling Library
90100

docs/library/stdlib.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Standard libraries
2+
3+
These are libraries that came bundled with ZX Basic Compiler.
4+
Some libraries might be available only for some architectures. If so,
5+
they will be signaled as such. If no notice is shown, they are available for
6+
all.
7+
8+
* [string.bas](../library/string.bas.md)<br />
9+
Library for string manipulation.

docs/library/string.bas.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# STRING.BAS
2+
3+
Library for generic string manipulation in Boriel ZX BASIC.
4+
5+
By default, the first character in a ZX BASIC string starts at position 0.
6+
This is not very common in many BASIC dialects (i.e. Sinclair BASIC) were strings
7+
start at position 1. This is done by efficiency. If you want your strings
8+
to start at position 1, compile with `--string-base=1`.
9+
10+
11+
### String slicing
12+
Functions to retrieve a substring from a string:
13+
14+
* [left](../string/left)
15+
* [mid](../string/mid)
16+
* [right](../string/right)

docs/library/string/left.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# LEFT
2+
3+
Library: `#include <string.bas>`
4+
5+
Returns the first n chars of a string
6+
7+
8+
###Syntax
9+
`left(s$, N)`
10+
11+
Returns a substring of s$ of at most `N` characters starting from the left side.
12+
13+
* If the string length is shorter than `N`, the entire string will be returned.
14+
15+
`left(s$, N)` is equivalent to `s$(TO N - 1)`
16+
17+
## Examples
18+
19+
```basic
20+
#include <string.bas>
21+
22+
PRINT left("HELLO WORLD", 5)
23+
```
24+
Will print `HELLO`.
25+
26+
---
27+
28+
```basic
29+
#include <string.bas>
30+
31+
PRINT left("HELLO WORLD", 20)
32+
```
33+
This will print `HELLO WORLD`. Despite asking for 20 chars, the string contains
34+
just 11 chars, so we get the entire string (they won't be filled with spaces).
35+
36+
37+
### See also
38+
39+
* [mid](mid.md)
40+
* [right](right.md)
41+
42+
43+
Back to parent page: [String library](../string.bas.md)

docs/library/string/mid.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# MID
2+
3+
Library: `#include <string.bas>`
4+
5+
Return a portion of a string.
6+
7+
8+
###Syntax
9+
`mid(s$, start, N)`
10+
11+
Returns a substring of s$ of at most `N` characters starting at the given
12+
`start` position.
13+
14+
* If the string length is shorter than `start + N` position (the `end` position is
15+
beyond the end of the string), the substring starting from `start` position will
16+
be returned.
17+
18+
* If the start position is beyond the end of the string, an empty string
19+
will be returned.
20+
21+
`mid(s$, start, N)` is equivalent to `s$(start TO start + N - 1)`
22+
23+
## Examples
24+
25+
```basic
26+
#include <string.bas>
27+
28+
PRINT mid("HELLO WORLD", 0, 5)
29+
```
30+
Will print `HELLO`.
31+
32+
---
33+
34+
```basic
35+
#include <string.bas>
36+
37+
PRINT mid("HELLO WORLD", 6, 8)
38+
```
39+
This will print just `WORLD`.
40+
It'll start at position 6-th (for a 0-based string this is 7-th char), and print
41+
up to 8 chars, but since there are only 5, it will get just `WORLD`.
42+
43+
---
44+
45+
```basic
46+
#include <string.bas>
47+
48+
PRINT mid("HELLO WORLD", 12, 5)
49+
```
50+
This will print just an empty string: start position is beyond the end
51+
of the string.
52+
53+
54+
### See also
55+
56+
* [left](left.md)
57+
* [right](right.md)
58+
59+
60+
Back to parent page: [String library](../string.bas.md)

docs/library/string/right.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# RIGHT
2+
3+
Library: `#include <string.bas>`
4+
5+
Returns the last n chars of a string
6+
7+
8+
###Syntax
9+
`right(s$, N)`
10+
11+
Returns a substring of s$ of at most `N` characters starting from the right side.
12+
13+
* If the string length is shorter than `N`, the entire string will be returned.
14+
15+
`right(s$, N)` is equivalent to `s$(len(s$) - N - 1 TO)`
16+
17+
## Examples
18+
19+
```basic
20+
#include <string.bas>
21+
22+
PRINT right("HELLO WORLD", 5)
23+
```
24+
Will print `WORLD`.
25+
26+
---
27+
28+
```basic
29+
#include <string.bas>
30+
31+
PRINT left("HELLO WORLD", 20)
32+
```
33+
This will print `HELLO WORLD`. Despite asking for 20 chars, the string contains
34+
just 11 chars, so we get the entire string (they won't be filled with spaces).
35+
36+
37+
### See also
38+
39+
* [left](left.md)
40+
* [mid](mid.md)
41+
42+
43+
Back to parent page: [String library](../string.bas.md)

0 commit comments

Comments
 (0)