<!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 - ltrim_dollar - String">
<title>ltrim_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> / ltrim_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="ltrim-function">LTrim$ Function</h1>
<p>Returns a <code>String</code> containing a copy of a specified string with leading spaces removed.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">LTrim$(string)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>string</code>: Required. Any valid string expression. If <code>string</code> contains <code>Null</code>, <code>Null</code> is returned.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a <code>String</code> with all leading (left-side) spaces removed. If the string contains only spaces, returns an empty string. Trailing spaces and spaces within the string are preserved.</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>LTrim$</code> function removes leading space characters (ASCII 32) from a string. It's commonly used to clean up user input, process fixed-width data, or normalize strings for comparison.
Only the space character (ASCII 32) is removed. Other whitespace characters like tabs, newlines, or non-breaking spaces are not affected by <code>LTrim$</code>.
<code>LTrim$</code> is the string-specific version that always returns a <code>String</code>. The <code>LTrim</code> function returns a <code>Variant</code>.</p>
<h2 id="typical-uses">Typical Uses</h2>
<h3 id="example-1-cleaning-user-input">Example 1: Cleaning User Input</h3>
<pre><code class="language-vbnet">Dim userInput As String
userInput = " John Doe"
cleaned = LTrim$(userInput) ' "John Doe"</code></pre>
<h3 id="example-2-processing-fixed-width-data">Example 2: Processing Fixed-Width Data</h3>
<pre><code class="language-vbnet">Dim record As String
record = " 12345"
id = LTrim$(record) ' "12345"</code></pre>
<h3 id="example-3-normalizing-comparison">Example 3: Normalizing Comparison</h3>
<pre><code class="language-vbnet">If LTrim$(text1) = LTrim$(text2) Then
Debug.Print "Match (ignoring leading spaces)"
End If</code></pre>
<h3 id="example-4-parsing-indented-text">Example 4: Parsing Indented Text</h3>
<pre><code class="language-vbnet">Dim line As String
line = " Code line"
code = LTrim$(line) ' "Code line"</code></pre>
<h2 id="common-usage-patterns">Common Usage Patterns</h2>
<h3 id="validating-non-empty-input">Validating Non-Empty Input</h3>
<pre><code class="language-vbnet">Dim name As String
name = txtName.Text
If LTrim$(name) = "" Then
MsgBox "Name cannot be empty or spaces only"
End If</code></pre>
<h3 id="processing-csv-fields">Processing CSV Fields</h3>
<pre><code class="language-vbnet">Dim fields() As String
fields = Split(csvLine, ",")
For i = 0 To UBound(fields)
fields(i) = LTrim$(fields(i))
Next i</code></pre>
<h3 id="reading-indented-configuration">Reading Indented Configuration</h3>
<pre><code class="language-vbnet">Dim configLine As String
configLine = " setting=value"
setting = LTrim$(configLine) ' "setting=value"</code></pre>
<h3 id="extracting-list-items">Extracting List Items</h3>
<pre><code class="language-vbnet">Dim listItem As String
listItem = " - Item text"
text = LTrim$(listItem) ' "- Item text"</code></pre>
<h3 id="database-field-cleanup">Database Field Cleanup</h3>
<pre><code class="language-vbnet">Dim dbValue As String
dbValue = rs.Fields("name").Value
cleanValue = LTrim$(dbValue)</code></pre>
<h3 id="removing-formatting-spaces">Removing Formatting Spaces</h3>
<pre><code class="language-vbnet">Dim formatted As String
formatted = " $1,234.56"
amount = LTrim$(formatted) ' "$1,234.56"</code></pre>
<h3 id="processing-text-file-lines">Processing Text File Lines</h3>
<pre><code class="language-vbnet">Dim line As String
Open "data.txt" For Input As #1
Do Until EOF(1)
Line Input #1, line
line = LTrim$(line)
If Left$(line, 1) <> "#" Then
processLine line
End If
Loop
Close #1</code></pre>
<h3 id="normalizing-string-arrays">Normalizing String Arrays</h3>
<pre><code class="language-vbnet">Dim items() As String
items = Split(data, vbCrLf)
For i = 0 To UBound(items)
items(i) = LTrim$(items(i))
Next i</code></pre>
<h3 id="removing-padding-from-fixed-fields">Removing Padding from Fixed Fields</h3>
<pre><code class="language-vbnet">Dim fixedRecord As String
fixedRecord = " Customer Name "
name = LTrim$(fixedRecord) ' "Customer Name "</code></pre>
<h3 id="combining-with-rtrim-for-full-trim">Combining with <code>RTrim</code>$ for Full Trim</h3>
<pre><code class="language-vbnet">Dim text As String
text = " Data "
' Remove both leading and trailing spaces
cleaned = LTrim$(RTrim$(text)) ' "Data"
' Or use Trim$ directly
cleaned = Trim$(text) ' "Data"</code></pre>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>LTrim</code>: Variant version that returns a <code>Variant</code></li>
<li><code>RTrim$</code>: Removes trailing spaces from a string</li>
<li><code>Trim$</code>: Removes both leading and trailing spaces</li>
<li><code>Left$</code>: Returns characters from the left side of a string</li>
<li><code>Len</code>: Returns the length of a string</li>
<li><code>Replace</code>: Replaces occurrences of a substring</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li>Use <code>Trim$</code> instead of <code>LTrim$</code> when you want to remove both leading and trailing spaces</li>
<li>Always validate input after trimming to check for empty strings</li>
<li>Be aware that only space characters (ASCII 32) are removed, not tabs or other whitespace</li>
<li>Use <code>LTrim$</code> for left-aligned fixed-width fields</li>
<li>Combine with validation to prevent injection attacks in SQL or scripts</li>
<li>Remember that <code>LTrim$</code> preserves internal and trailing spaces</li>
<li>Consider using <code>Replace</code> for removing other whitespace characters</li>
<li>Cache the result if using trimmed value multiple times</li>
<li>Use <code>LTrim$</code> instead of <code>LTrim</code> when you need explicit <code>String</code> type</li>
<li>Test with edge cases: empty strings, all spaces, no leading spaces</li>
</ol>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li><code>LTrim$</code> is a fast operation in VB6</li>
<li>No performance penalty if the string has no leading spaces</li>
<li>More efficient than using <code>Replace</code> or manual character removal</li>
<li>Minimal memory allocation if few spaces are removed</li>
<li>Consider caching trimmed values in loops for better performance</li>
</ul>
<h2 id="whitespace-handling">Whitespace Handling</h2>
<table>
<thead>
<tr>
<th>Character</th>
<th>ASCII</th>
<th>Removed by <code>LTrim</code>$</th>
</tr>
</thead>
<tbody>
<tr>
<td>Space</td>
<td>32</td>
<td>Yes (if leading)</td>
</tr>
<tr>
<td>Tab</td>
<td>9</td>
<td>No</td>
</tr>
<tr>
<td>Newline</td>
<td>10</td>
<td>No</td>
</tr>
<tr>
<td>Carriage Return</td>
<td>13</td>
<td>No</td>
</tr>
<tr>
<td>Non-breaking Space</td>
<td>160</td>
<td>No</td>
</tr>
<tr>
<td>Vertical Tab</td>
<td>11</td>
<td>No</td>
</tr>
<tr>
<td>Form Feed</td>
<td>12</td>
<td>No</td>
</tr>
</tbody>
</table>
<h2 id="common-pitfalls">Common Pitfalls</h2>
<ul>
<li>Assuming <code>LTrim$</code> removes all whitespace characters (it only removes spaces)</li>
<li>Not checking for empty string after trimming spaces-only input</li>
<li>Using <code>LTrim$</code> when <code>Trim$</code> would be more appropriate</li>
<li>Forgetting that trailing spaces are preserved</li>
<li>Not handling <code>Null</code> string values (causes runtime error)</li>
<li>Assuming trimmed string is never empty</li>
<li>Using repeatedly in loops without caching result</li>
<li>Expecting tabs or newlines to be removed</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Only removes space characters (ASCII 32), not other whitespace</li>
<li>Cannot specify which characters to remove</li>
<li>Does not remove trailing spaces (use <code>RTrim$</code> or <code>Trim$</code>)</li>
<li>Returns <code>Null</code> if the string argument is <code>Null</code></li>
<li>Cannot remove spaces from the middle of strings</li>
<li>No option to limit how many spaces are removed</li>
<li>Does not normalize multiple internal spaces to single spaces</li>
</ul>
</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>