Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string operators and s.expandpath
#1
The QM 2.1.4(beta) help topic "Strings" gives this example
Code:
Copy      Help
str s = "Cat"
out s
s + " and Mouse"
out s
s - "Dog, "
out s
which when run, gives
  • Cat
    Cat and Mouse
    Dog, Cat and Mouse
Does anyone know why a like use of string operators
Code:
Copy      Help
str ss s.expandpath("$Desktop$")
out s
ss = s + "\myfile.txt"
out ss
ss = "\myfile.txt" - s
out ss
gives integers instead of strings?
  • C:\Documents and Settings\MyUserName\Desktop
    24075838
    2886202
Thanks, -John
#2
Operator + in QM does not join strings when used with =. To join two or more strings, use ss.from(s s2 ...).

When you use ss=s+s2, s is interpreted as lpstr (pointer to first character), and second operand is added to it as integer, like in C. For example

str s="abc"
out s+1

outputs "bc", because pointer is moved by 1 character.

If both operands are strings or pointers, result is integer.


BTW, you can use this:

str s.expandpath("$Desktop$\myfile.txt")
#3
So i+1 increments i? I'm used to languages that require i=i+1. Perhaps that's why I just missed the difference here, thinking instead it was a problem with s.expand. Thanks for the tip on s.expand--missed that too.
QM is looking better all the time--once I get a little further on my programming, I'll test if QM window triggers are low enough overhead to trap errors and do some other control chores for two chromatography systems simultaneously running on a small Win98 machine. As it is, a rare serial port error freezes one of them until an OK button is pushed, not great for unattended (overnight) operation! I've got QM pushing "OK" me, and if the error recurs 3X in a row, well...Idea..., I'll just have QM dial my cell phone and give me a shout!
Aciu! -John


Forum Jump:


Users browsing this thread: 1 Guest(s)