Op 9/08/2024 om 7:52 schreef Wolfgang Lenerz via Ql-Users:
Hi,

without having looked at the string slicing code in SMSQE, I believe that the general contract is a$(x to y) where x and y are positive integers and y is bigger than, or equal to, x. If x is omitted, it is implied that it should be 1. If y is omitted, it is implied that it should be the size of the string (this explains j$ and k$).

So the examples where x is bigger than y will either return nothing (when x=y-1) or an error - as these are non-sensical in regard of the above contract, that doesn't bother me. This is why the line i$=a$(L to L-2) fails: x is bigger than y.


By exception, a$(0) returns the length of a$, so in the line d$=a$(0), d$ isn't 1, but 10. This is also why your line e$=a$(0 to 1) fails.


Notes:

1 - If y is bigger than the size of the string, no error is generated, and it will be limited to the length of the string: Print a$(1 to 100) will just print the entire string.

2 - Fun can be had with negative numbers - Norman Dunbar drew my attention to that.


print a$(1 to -1) will print the entire string. I PRESUME that this is because both indexes get taken as unsigned integers, so -1 would be $ffffffff, and thus bigger than the end of the string....

HTH

Wolfgang


100 open#3,con_:window#3,800,600,0,0

105 REMark test done from within QD

110 a$ = "1234567890"

115 L=len(a$)

120 b$ = a$(4 to 3): REMark This works but b$ is empty

125 rem c$ = a$(4 to 2): REMark This fails with an error.

130

135 d$=a$(0) :REMark returns 1 OK WHY?

140 REMark e$=a$(0 to 1) :REMark This fails with an error.

145 f$=a$(1) :REMark This works

150 g$=a$(L) :REMark This works

155 h$=a$(L-1 to l) :REMark This works

160 REMark i$=a$(L to L-2) :REMark This fails with an error.

165 j$=a$( to 2)

170 k$=a$( to )

175 print#3, 'b$= ';b$,len(b$)

180 print#3, 'c$: ';c$ :REMark This fails with an error.

185 print#3, 'd$= ';d$ :REMark This works

190 print#3, 'e$= ';e$ ,len(e$)

195 print#3, 'f$= ';f$

200 print#3, 'g$= ';g$

205 print#3, 'h$= ';h$

210 print#3, 'i$= ';i$
çois
215 print#3, 'j$= ';j$

220 print#3, 'k$= ';k$ ::REMark This works returns a$

225 print#3, 'done'

230 pause

_______________________________________________
QL-Users Mailing List

Hi Wolfgang,

Thank you for reply and explanation.

Have a fine day.

François Van Emelen

_______________________________________________
QL-Users Mailing List

Reply via email to