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
Lysit
Newbie


Joined: 13 Jul 2005
Posts: 7

PostPosted: Thu Jul 23, 2009 12:30 pm   

Removing linefeeds/carriage returns
 
For a remote app im working on I send it a date string like this.
Y09M07D23H13N15S03

Where M=months, N=minutes. For testing I made the following

#ECHOP Y%time(y)
#if (%time(m)<10) {#ECHOP M0%time(m)} {#ECHOP M%time(m)}
#if (%time(d)<10) {#ECHOP D0%time(d)} {#ECHOP D%time(d)}
#if (%time(h)<10) {#ECHOP H0%time(h)} {#ECHOP H%time(h)}
#if (%time(n)<10) {#ECHOP N0%time(n)} {#ECHOP N%time(n)}
#if (%time(s)<10) {#Echo S0%time(s)} {#Echo S%time(s)}

This creates a string in the correct format, without sending it (I made this to test the theory). Now I want to send the string so I tried the following

Y%time(y)
#if (%time(m)<10) {M0%time(m)} {M%time(m)}
#if (%time(d)<10) {D0%time(d)} {D%time(d)}
#if (%time(h)<10) {H0%time(h)} {H%time(h)}
#if (%time(n)<10) {N0%time(n)} {N%time(n)}
#if (%time(s)<10) {S0%time(s)} {S%time(s)}

However this sends:
Y 09
M0 7
D 23
H 13
N 19
S 40

I'd like to know how I could remove the linefeeds/carriage returns and spaces, so it looks more like the #echo/#echop version
Reply with quote
Tech
GURU


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

PostPosted: Thu Jul 23, 2009 6:02 pm   
 
My friend, it's time you discovered the %concat and the %if functions.

You can use the former to keep appending to variable and then send the variable (string) at the end of the calculations. You can use the latter function to combine it all into one command.
_________________
Asati di tempari!
Reply with quote
Lysit
Newbie


Joined: 13 Jul 2005
Posts: 7

PostPosted: Thu Jul 23, 2009 6:25 pm   
 
Do you have an example? The ones in the help file are generally of a limited scope, for example, I see how it prints a string, I see how basically the if works, I don't see how to use the if to append strings, or flush it before use. Does the string require a Null termnator? etc.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Jul 23, 2009 7:56 pm   
 
Basically, you have two options. The first is to start off with a variable and fill it dependant on your variables, and then print it:

$string = ""
#if (@var1=1) {$string=%concat($string,"Variable 1 is On")} {$string=%concat($string,"Variable 1 is Off")}
#if (@var2=1) {$string=%concat($string," Variable 2 is On")} {$string=%concat($string," Variable 2 is Off")}
#echo $string

Note the spaces to keep the formatting of the variable pretty. The other alternative is to use %if to control a single #echo command:

#echo %concat("Variable 1 is ",%if(@var1=1,"On","Off")," Variable 2 is ",%if(@var1=1,"On","Off"))

These examples are functionally identical - it's up to you what you'd rather do. Give var1 and var2 some values and try this code to see what it does.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Jul 24, 2009 1:12 am   
 
Per the help for %time you can use two characters in the time string to format it as a zero filled string. Finally there is an undocumented thing, single quotes can be used to block the interpretation of time characters.

#SHOW %time("'Y'yy'M'mm'D'dd'H'hh'N'nn'S'ss")

To send it you would use the #SEND command.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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