mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 22:28:16 +01:00
added sub_str
This commit is contained in:
parent
1eb7daaf08
commit
c8193baa20
@ -38,7 +38,8 @@ Some modules may depend on other modules. For example, the `polyline2d` module d
|
|||||||
|
|
||||||
- Functon
|
- Functon
|
||||||
- [rotate_p](https://openhome.cc/eGossip/OpenSCAD/lib-rotate_p.html)
|
- [rotate_p](https://openhome.cc/eGossip/OpenSCAD/lib-rotate_p.html)
|
||||||
|
- [sub_str](https://openhome.cc/eGossip/OpenSCAD/lib-sub_str.html)
|
||||||
|
|
||||||
- Path
|
- Path
|
||||||
- [circle_path](https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html)
|
- [circle_path](https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html)
|
||||||
- [bezier](https://openhome.cc/eGossip/OpenSCAD/lib-bezier.html)
|
- [bezier](https://openhome.cc/eGossip/OpenSCAD/lib-bezier.html)
|
||||||
|
14
docs/lib-sub_str.md
Normal file
14
docs/lib-sub_str.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# sub_str
|
||||||
|
|
||||||
|
Returns a new string that is a substring of the given string.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `t` : The original string.
|
||||||
|
- `begin` : The beginning index, inclusive.
|
||||||
|
- `end` : The ending index, exclusive. If it's omitted, the substring begins with the character at the specified `begin` and extends to the end of this string.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
echo(sub_str("helloworld", 0, 5)); // ECHO: "hello"
|
||||||
|
echo(sub_str("helloworld", 5)); // ECHO: "world"
|
17
src/sub_str.scad
Normal file
17
src/sub_str.scad
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* sub_str.scad
|
||||||
|
*
|
||||||
|
* Returns a new string that is a substring of the given string.
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2017
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib-sub_str.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
function sub_str(t, begin, end, result = "") =
|
||||||
|
end == undef ? sub_str(t, begin, len(t)) : (
|
||||||
|
begin == end ? result : sub_str(t, begin + 1, end, str(result, t[begin]))
|
||||||
|
);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user