|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sun May 04, 2008 2:22 pm
%trim removes only some types of whitespace |
It appears that the %trim function only removes leading and trailing spaces (%char(32)) and not whitespaces in general.
Maybe this is by design, and if so I'd like to request that it be made to remove any leading and trailing whitespaces
Code: |
#echo %trim(%format("This string ends with a tab%s",%char(9)))This is the next string |
Result:
Code: |
This string ends with a tab This is the next string |
Code: |
#echo %trim(%format("This string ends with \r\n%s",%crlf))This is the next string |
Result:
Code: |
This string ends with \r\n
This is the next string |
In both cases the trailing whitespaces are ignored by %trim. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Sun May 04, 2008 2:37 pm |
Agreed, they should be removed imho
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun May 04, 2008 3:05 pm |
I am not quite sure what you expect different with this example
Code: |
#echo %trim(%format("This string ends with \r\n%s",%crlf))This is the next string |
You should be able to do this with %subregex as of the next public version, I believe the \h pattern code was not available in the 2.18 version
Code: |
#SHOW %subregex(%concat(" ",%char(9),"Text",%char(9),%crlf,%char(9),"text 2"),"^\h+|\h+$","xxx") |
I used 'xxx' for visibility of the replacements, you would ofcourse use a null replacement.
Edit: I just noticed this was likely inregards to something going on in the Python DB thread. A more appropiate, untested replacement might be
Code: |
#SHOW %subregex(%concat(" ",%char(9),"Text",%char(9),%crlf,%char(9),"text 2"),"(\A)?(?:\h|\v)+(?(1)|\Z)","xxx") |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sun May 04, 2008 4:03 pm |
Vijilante wrote: |
I am not quite sure what you expect different with this example
Code: |
#echo %trim(%format("This string ends with \r\n%s",%crlf))This is the next string |
|
What I expected was this
Code: |
This string ends with \r\nThis is the next string |
That is I expected the carriage return\ linefeed at the end of the first string to be removed.
I was able to achieve it with this function
Code: |
#FUNCTION trimws($orig_str) {#RETURN %subregex($orig_str,"(\A\s+)|(\s+\Z)")} |
But really I had expected %trim to remove trailing and leading whitespaces of any sort and was surprised when it did not. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sun May 04, 2008 11:11 pm |
The helpfile does only say spaces, but I agree that it would be a useful update/feature for it to remove all whitespace ([ \t\r\n] -- spaces, tabs, any kind of return or linefeed).
|
|
|
|
|
|