Difference between revisions of "LTRIM$"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m (reword)
imported>SMcNeill
(style guidelines)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
The {{KW|LTRIM$}} function removes leading space characters from a {{KW|STRING}} value.
The [[LTRIM$]] function removes leading space characters from a [[STRING]] value.




{{PageSyntax}}
{{PageSyntax}}
:<code>''return$'' = {{KW|LTRIM$}}({{Parameter|value$}})</code>
:{{Parameter|return$}} = [[LTRIM$]]({{Parameter|text$}})




{{PageDescription}}
{{PageDescription}}
* {{Parameter|value$}} is the {{KW|STRING}} value to trim.
* {{Parameter|text$}} is the [[STRING]] value to trim.
* If {{Parameter|value$}} contains no leading space characters, {{Parameter|value$}} is returned unchanged.
* If {{Parameter|text$}} contains no leading space characters, it is returned unchanged.
* Convert fixed length {{KW|STRING}} values by using a different {{parameter|return$}} variable.
* Convert fixed length [[STRING]] values by using a different {{parameter|return$}} variable.
* Can be used to trim a positive numerical value converted to a string value by {{KW|STR$}}.
* Can be used to trim the leading space of a positive numerical value converted to a string value by [[STR$]].
 




{{PageExamples}}
{{PageExamples}}
 
''Example 1:'' Trimming a positive string number.
Trimming a fixed length string value for use by another string variable:
{{CodeStart}}
{{CodeStart}}
name$ = {{Cl|LTRIM$}}(contact.name) ' trims spaces from front of fixed length {{Cl|TYPE}} value.
value = 12345
{{CodeEnd}}
number$ = {{Cl|LTRIM$}}({{Cl|STR$}}(value)) 'converting number to string removes right PRINT space
 
{{Cl|PRINT}} "[" + number$ + "]" '' ''
 
 
Trimming a positive string number:
{{CodeStart}}
number$ = {{Cl|LTRIM$}}({{Cl|STR$}}(value))
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}[12345]
{{OutputEnd}}




Trimming 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
some text
some text
{{OutputEnd}}
''Example 3:'' A TRIM$ function to trim spaces off of both ends of a string.
{{codeStart}} '' ''
text$ = "        Text String          "
trimmed$ = TRIM$(text$)
{{Cl|PRINT}} {{Cl|CHR$}}(26) + trimmed$ + {{Cl|CHR$}}(27) '' ''
{{Cl|FUNCTION}} TRIM$(text$)
TRIM$ = {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$))
{{Cl|END FUNCTION}} '' ''
{{CodeEnd}}
{{OutputStart}}→Text String←
{{OutputEnd}}
{{OutputEnd}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* {{KW|RTRIM$}}
* [[RTRIM$]], [[STR$]]
* {{KW|STR$}}
* [[LEFT$]], [[RIGHT$]]
* {{KW|HEX$}}
* [[HEX$]], [[MID$]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 02:46, 10 October 2017

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:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page