<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="VB6Parse Library Reference - mid_dollar - String">
<title>mid_dollar - String - VB6Parse Library Reference</title>
<link rel="stylesheet" href="../../../assets/css/style.css">
<link rel="stylesheet" href="../../../assets/css/docs-style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="../../../assets/js/theme-switcher.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
<header class="docs-header">
<div class="container">
<h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/string/index.html">String</a> / mid_dollar</h1>
<p class="tagline">VB6 Library Reference</p>
</div>
</header>
<nav class="docs-nav">
<div class="container">
<a href="../../../index.html">Home</a>
<a href="../../../library/index.html">Library Reference</a>
<a href="../../../documentation.html">Documentation</a>
<a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
<a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
<span class="theme-icon">🌙</span>
</button>
</div>
</nav>
<main class="container">
<article class="library-item">
<h1 id="mid-function">Mid$ Function</h1>
<p>The <code>Mid$</code> function returns a <code>String</code> containing a specified number of characters from a string.
The dollar sign suffix (<code>$</code>) indicates that this function always returns a <code>String</code> type, never a <code>Variant</code>.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">Mid$(string, start[, length])</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>string</code> - Required. <code>String</code> expression from which characters are returned.</li>
<li><code>start</code> - Required. <code>Long</code>. Character position in <code>string</code> at which the part to be taken begins (1-based).</li>
<li><code>length</code> - Optional. <code>Long</code>. Number of characters to return. If omitted or if there are fewer than <code>length</code> characters in the text (including the character at <code>start</code>), all characters from the start position to the end of the string are returned.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a <code>String</code> containing the specified portion of the input string.</p>
<h2 id="behavior">Behavior</h2>
<ul>
<li>If <code>start</code> is greater than the number of characters in <code>string</code>, <code>Mid$</code> returns a zero-length string ("").</li>
<li>If <code>start</code> is less than 1, a runtime error occurs.</li>
<li>If <code>length</code> is negative, a runtime error occurs.</li>
<li>The first character in the string is at position 1.</li>
</ul>
<h2 id="difference-from-mid">Difference from Mid</h2>
<p>The <code>Mid$</code> function always returns a <code>String</code>, while the <code>Mid</code> function (without the dollar sign) can return a <code>Variant</code>.
In practice, they behave identically in most scenarios, but the dollar sign version may be slightly more efficient
as it avoids the overhead of the <code>Variant</code> type.</p>
<h2 id="examples">Examples</h2>
<pre><code class="language-vbnet">' Extract 3 characters starting at position 2
Dim result As String
result = Mid$("Hello World", 2, 3) ' Returns "ell"
' Extract from position 7 to the end
result = Mid$("Hello World", 7) ' Returns "World"
' Start position beyond string length
result = Mid$("Hi", 10) ' Returns ""</code></pre>
</article>
<div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
<p>
<a href="index.html">← Back to String</a> |
<a href="../index.html">View all functions</a>
</p>
</div>
</main>
<footer>
<div class="container">
<p>© 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
</div>
</footer>
</body>
</html>