This repository has been archived by the owner on May 21, 2024. It is now read-only.
forked from boriel-basic/zxbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request boriel-basic#569 from boriel/docs
doc: start of string.bas library documentation
- Loading branch information
Showing
9 changed files
with
445 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Standard libraries | ||
|
||
These are libraries that came bundled with ZX Basic Compiler. | ||
Some libraries might be available only for some architectures. If so, | ||
they will be signaled as such. If no notice is shown, they are available for | ||
all. | ||
|
||
* [string.bas](../library/string.bas.md)<br /> | ||
Library for string manipulation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# STRING.BAS | ||
|
||
Library for generic string manipulation in Boriel ZX BASIC. | ||
|
||
By default, the first character in a ZX BASIC string starts at position 0. | ||
This is not very common in many BASIC dialects (i.e. Sinclair BASIC) were strings | ||
start at position 1. This is done by efficiency. If you want your strings | ||
to start at position 1, compile with `--string-base=1`. | ||
|
||
|
||
### String slicing | ||
Functions to retrieve a substring from a string: | ||
|
||
* [left](../string/left) | ||
* [mid](../string/mid) | ||
* [right](../string/right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# LEFT | ||
|
||
Library: `#include <string.bas>` | ||
|
||
Returns the first n chars of a string | ||
|
||
|
||
###Syntax | ||
`left(s$, N)` | ||
|
||
Returns a substring of s$ of at most `N` characters starting from the left side. | ||
|
||
* If the string length is shorter than `N`, the entire string will be returned. | ||
|
||
`left(s$, N)` is equivalent to `s$(TO N - 1)` | ||
|
||
## Examples | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT left("HELLO WORLD", 5) | ||
``` | ||
Will print `HELLO`. | ||
|
||
--- | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT left("HELLO WORLD", 20) | ||
``` | ||
This will print `HELLO WORLD`. Despite asking for 20 chars, the string contains | ||
just 11 chars, so we get the entire string (they won't be filled with spaces). | ||
|
||
|
||
### See also | ||
|
||
* [mid](mid.md) | ||
* [right](right.md) | ||
|
||
|
||
Back to parent page: [String library](../string.bas.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# MID | ||
|
||
Library: `#include <string.bas>` | ||
|
||
Return a portion of a string. | ||
|
||
|
||
###Syntax | ||
`mid(s$, start, N)` | ||
|
||
Returns a substring of s$ of at most `N` characters starting at the given | ||
`start` position. | ||
|
||
* If the string length is shorter than `start + N` position (the `end` position is | ||
beyond the end of the string), the substring starting from `start` position will | ||
be returned. | ||
|
||
* If the start position is beyond the end of the string, an empty string | ||
will be returned. | ||
|
||
`mid(s$, start, N)` is equivalent to `s$(start TO start + N - 1)` | ||
|
||
## Examples | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT mid("HELLO WORLD", 0, 5) | ||
``` | ||
Will print `HELLO`. | ||
|
||
--- | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT mid("HELLO WORLD", 6, 8) | ||
``` | ||
This will print just `WORLD`. | ||
It'll start at position 6-th (for a 0-based string this is 7-th char), and print | ||
up to 8 chars, but since there are only 5, it will get just `WORLD`. | ||
|
||
--- | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT mid("HELLO WORLD", 12, 5) | ||
``` | ||
This will print just an empty string: start position is beyond the end | ||
of the string. | ||
|
||
|
||
### See also | ||
|
||
* [left](left.md) | ||
* [right](right.md) | ||
|
||
|
||
Back to parent page: [String library](../string.bas.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# RIGHT | ||
|
||
Library: `#include <string.bas>` | ||
|
||
Returns the last n chars of a string | ||
|
||
|
||
###Syntax | ||
`right(s$, N)` | ||
|
||
Returns a substring of s$ of at most `N` characters starting from the right side. | ||
|
||
* If the string length is shorter than `N`, the entire string will be returned. | ||
|
||
`right(s$, N)` is equivalent to `s$(len(s$) - N - 1 TO)` | ||
|
||
## Examples | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT right("HELLO WORLD", 5) | ||
``` | ||
Will print `WORLD`. | ||
|
||
--- | ||
|
||
```basic | ||
#include <string.bas> | ||
PRINT left("HELLO WORLD", 20) | ||
``` | ||
This will print `HELLO WORLD`. Despite asking for 20 chars, the string contains | ||
just 11 chars, so we get the entire string (they won't be filled with spaces). | ||
|
||
|
||
### See also | ||
|
||
* [left](left.md) | ||
* [mid](mid.md) | ||
|
||
|
||
Back to parent page: [String library](../string.bas.md) |
Oops, something went wrong.