35 lines
No EOL
2.4 KiB
HTML
35 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Text.slice — Ludic</title>
|
||
<meta name="description" content="A substring covering bytes [a, b).">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-text.html">Text</a> <span>›</span> <span class="here">Text.slice</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-method">method</span>
|
||
<h1 id="top">Text.slice</h1>
|
||
</div>
|
||
<code class="sig">Text.slice(s, a, b) -> string</code>
|
||
<div class="desc"><p>Returns a fresh string of the bytes from index <code>a</code> up to but not including <code>b</code> — the half-open range <code>[a, b)</code>, so <code>Text.slice("hello world", 0, 5)</code> is <code>"hello"</code>. It is the call form of the <code>s[a..b]</code> slice syntax and allocates a new string. Use it to cut a fixed-width field, drop a prefix, or take the first few characters of a name.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-s"><code class="pname">s</code><span class="pdesc">the source string</span></div><div class="param" id="param-a"><code class="pname">a</code><span class="pdesc">the start byte index (inclusive)</span></div><div class="param" id="param-b"><code class="pname">b</code><span class="pdesc">the end byte index (exclusive)</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program FirstWord {
|
||
var line: string = "hello world"
|
||
|
||
handler Split phase Update {
|
||
let space = Text.index_of(line, " ") # 5
|
||
let word = Text.slice(line, 0, space) # "hello"
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |