Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Yodous
Apprentice


Joined: 23 Jun 2004
Posts: 105
Location: Poland

PostPosted: 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
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Yodous
Apprentice


Joined: 23 Jun 2004
Posts: 105
Location: Poland

PostPosted: 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?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Oct 15, 2009 2:39 am   
 
Try this instead.
Code:
#show %ansi(10)%format("%30s", "on")

_________________
Asati di tempari!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net