LTRIM$: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The LTRIM$ function removes leading space characters from a STRING value. {{PageSyntax}} :{{Parameter|return$}} = LTRIM$({{Parameter|text$}}) {{PageDescription}} * {{Parameter|text$}} is the STRING value to trim. * If {{Parameter|text$}} contains no leading space characters, it is returned unchanged. * Convert fixed length STRING values by using a different {{parameter|return$}} variable. * Can be used to trim the leading space of a positive numer...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 18: Line 18:
value = 12345
value = 12345
number$ = {{Cl|LTRIM$}}({{Cl|STR$}}(value)) 'converting number to string removes right PRINT space
number$ = {{Cl|LTRIM$}}({{Cl|STR$}}(value)) 'converting number to string removes right PRINT space
{{Cl|PRINT}} "[" + number$ + "]" '' ''
{{Cl|PRINT}} "[" + number$ + "]"
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}[12345]
{{OutputStart}}[12345]
Line 25: Line 25:


''Example 2:'' Trimming leading spaces from text strings.
''Example 2:'' Trimming leading spaces from text strings.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|PRINT}} {{Cl|LTRIM$}}("some text")
{{Cl|PRINT}} {{Cl|LTRIM$}}("some text")
{{Cl|PRINT}} {{Cl|LTRIM$}}("  some text") '' ''
{{Cl|PRINT}} {{Cl|LTRIM$}}("  some text")
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}some text
{{OutputStart}}some text
Line 35: Line 35:


''Example 3:'' A TRIM$ function to trim spaces off of both ends of a string.
''Example 3:'' A TRIM$ function to trim spaces off of both ends of a string.
{{codeStart}} '' ''
{{codeStart}}
text$ = "        Text String          "
text$ = "        Text String          "
trimmed$ = TRIM$(text$)
trimmed$ = TRIM$(text$)
{{Cl|PRINT}} {{Cl|CHR$}}(26) + trimmed$ + {{Cl|CHR$}}(27) '' ''
{{Cl|PRINT}} {{Cl|CHR$}}(26) + trimmed$ + {{Cl|CHR$}}(27)
 
{{Cl|FUNCTION}} TRIM$(text$)
{{Cl|FUNCTION}} TRIM$(text$)
TRIM$ = {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$))
TRIM$ = {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$))
{{Cl|END FUNCTION}} '' ''
{{Cl|END FUNCTION}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}→Text String←
{{OutputStart}}→Text String←
Line 49: Line 48:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[RTRIM$]], [[STR$]]
* [https://qb64phoenix.com/forum/showthread.php?tid=1246 Featured in our "Keyword of the Day" series]
* [[_TRIM$]], [[RTRIM$]], [[STR$]]
* [[LEFT$]], [[RIGHT$]]
* [[LEFT$]], [[RIGHT$]]
* [[HEX$]], [[MID$]]
* [[HEX$]], [[MID$ (function)]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 17:40, 25 May 2024

The LTRIM$ function removes leading space characters from a STRING value.


Syntax

return$ = LTRIM$(text$)


Description

  • text$ is the STRING value to trim.
  • If text$ contains no leading space characters, it is returned unchanged.
  • Convert fixed length STRING values by using a different return$ variable.
  • Can be used to trim the leading space of a positive numerical value converted to a string value by STR$.


Examples

Example 1: Trimming a positive string number.

value = 12345
number$ = LTRIM$(STR$(value)) 'converting number to string removes right PRINT space
PRINT "[" + number$ + "]"
[12345]


Example 2: Trimming leading spaces from text strings.

PRINT LTRIM$("some text")
PRINT LTRIM$("   some text")
some text
some text


Example 3: A TRIM$ function to trim spaces off of both ends of a string.

text$ = "        Text String           "
trimmed$ = TRIM$(text$)
PRINT CHR$(26) + trimmed$ + CHR$(27)
FUNCTION TRIM$(text$)
TRIM$ = LTRIM$(RTRIM$(text$))
END FUNCTION
→Text String←


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link