18.4.0 released Sep 25, 2023
Trim string

Purpose: Trim a string.

trim-string <string> [ length [ define ] <new length> ] [ result [ define ] <result> ]

trim-string trims <string>, both on left and right. You can optionally get the length of the changed string by using "length" clause, in integer variable <new length>, which can be created with optional "define".

Without "result" clause, trimming is in place, i.e. if necessary the bytes within <string> are shifted to the left, and the result is <string>. With "result" clause,  <result> points to trimmed value within <string>, i.e. there is no movement of memory - this is a faster trim, but the pointer to the result is no longer <string>.
Examples
The variable "str" will be "some string" and "new_len" will be 11:
char str[] = "  some string  ";
trim-string str length define new_len

With "result" clause, the variable "str" will be "some string" and "new_len" will be 11, and "res" will point to (str+2):
char str[] = "  some string  ";
trim-string str length define new_len result define res

See also
Strings
copy-string  
count-substring  
lower-string  
num-string  
split-string  
trim-string  
upper-string  
write-string    
See all
documentation


You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a link back to this page (dofollow) - see full license at CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind.