 |
Yodous Apprentice
Joined: 23 Jun 2004 Posts: 105 Location: Poland
|
Posted: Wed Oct 14, 2009 8:19 pm
%len problem |
Hi there.
How can I check the length of the string, excluding some functions.
Code: |
#SA %len(%ansi(10)"One") |
Will return 13 instead of 3.
How can I check the length of the string, excluding functions.
Even when I made a function removeFunctionsFromString:
Code: |
#RETURN %subregex(%1, "%[a-z]+\(.+?\)", "") |
And check
Code: |
#SA %len(@removeFunctionsFromString(%ansi(10)"One")) |
It will return 13.
If there any other way to force this %len function to return 3, or maybe it can be included in the future by Zugg?
Best regards
Yodous |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Oct 14, 2009 8:25 pm |
This is because CMUD is evaluating the %ansi(10) *before* it gets passed to your @removeFunctionsFromString. So the string being passed is ESC[0;52;40mOne which has a length of 13. You can use the %stripansi function to strip the ANSI control codes from the string.
Code: |
#sa %len(%stripansi(%ansi(10)"One")) |
You cannot strip *any* function unless you first catch it before the function gets evaluated. And the only way to do that is if the function is just stored as a literal string, like:
Code: |
#VAR temp "%ansi(10)One" |
with quotes around the entire string. |
|
|
 |
Yodous Apprentice
Joined: 23 Jun 2004 Posts: 105 Location: Poland
|
Posted: Wed Oct 14, 2009 10:32 pm |
Ok, %stripansi() of course works.
But there is another question.
Why
Code: |
%format("%30s", %ansi(10)"on") |
gives different string than
Code: |
%format("%30s", "on") |
I would like to give the same thing hmm. Can it be done? |
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Oct 15, 2009 2:39 am |
Try this instead.
Code: |
#show %ansi(10)%format("%30s", "on") |
|
|
_________________ Asati di tempari! |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Oct 15, 2009 3:00 am |
%ansi(10)"on" is wrong. You at least need a + inbetween, but to do it formally you need to use the %concat(), like so:
%concat(%ansi(10),"on")
This, however, will change the length of your data string. If your data string is longer than the wildcard space you denoted in your format string, the wildcard space is ignored. |
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
|
|