TRIM$: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_TRIM$}} The _TRIM$ function removes both leading and trailing space characters from a STRING value. {{PageSyntax}} :{{Parameter|return$}} = _TRIM$({{Parameter|text$}}) {{PageDescription}} * Shorthand to using LTRIM$(RTRIM$("text")) * {{Parameter|text$}} is the STRING value to trim. * If {{Parameter|text$}} contains no leading or trailing space characters, it is returned unchanged. * Convert fixed length STRING values by usi...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 18: Line 18:
{{CodeStart}}
{{CodeStart}}
text$ = {{Cl|SPACE$}}(10) + "some text" + {{Cl|SPACE$}}(10)
text$ = {{Cl|SPACE$}}(10) + "some text" + {{Cl|SPACE$}}(10)
{{Cl|PRINT}} "[" + text$ + "]" '' ''
{{Cl|PRINT}} "[" + text$ + "]"
{{Cl|PRINT}} "[" + {{Cl|RTRIM$}}(text$) + "]" '' ''
{{Cl|PRINT}} "[" + {{Cl|RTRIM$}}(text$) + "]"
{{Cl|PRINT}} "[" + {{Cl|LTRIM$}}(text$) + "]" '' ''
{{Cl|PRINT}} "[" + {{Cl|LTRIM$}}(text$) + "]"
{{Cl|PRINT}} "[" + {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$)) + "]" '' ''
{{Cl|PRINT}} "[" + {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$)) + "]"
{{Cl|PRINT}} "[" + {{Cl|_TRIM$}}(text$) + "]" '' ''
{{Cl|PRINT}} "[" + {{Cl|_TRIM$}}(text$) + "]"
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}[          some text          ]
{{OutputStart}}[          some text          ]
Line 33: Line 33:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1246 Featured in our "Keyword of the Day" series]
* [[RTRIM$]], [[LTRIM$]]
* [[RTRIM$]], [[LTRIM$]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 17:43, 25 May 2024

The _TRIM$ function removes both leading and trailing space characters from a STRING value.


Syntax

return$ = _TRIM$(text$)


Description

  • Shorthand to using LTRIM$(RTRIM$("text"))
  • text$ is the STRING value to trim.
  • If text$ contains no leading or trailing space characters, it is returned unchanged.
  • Convert fixed length STRING values by using a different return$ variable.


Examples

Example: Demonstrating how _TRIM$(text$) can replace LTRIM$(RTRIM$(text$)):

text$ = SPACE$(10) + "some text" + SPACE$(10)
PRINT "[" + text$ + "]"
PRINT "[" + RTRIM$(text$) + "]"
PRINT "[" + LTRIM$(text$) + "]"
PRINT "[" + LTRIM$(RTRIM$(text$)) + "]"
PRINT "[" + _TRIM$(text$) + "]"
[          some text          ]
[          some text]
[some text          ]
[some text]
[some text]


See also



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