|
Lysit Newbie
Joined: 13 Jul 2005 Posts: 7
|
Posted: 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 |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
|
Lysit Newbie
Joined: 13 Jul 2005 Posts: 7
|
Posted: 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.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: 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 |
|
|
|
|
|