Substring: Difference between revisions

m
→‎Pascal: escape Semantic MediaWiki notation for emphasized text '' (two straight apostrophes back-to-back)
(→‎Pascal: forgot something in previous edit)
m (→‎Pascal: escape Semantic MediaWiki notation for emphasized text '' (two straight apostrophes back-to-back))
Line 3,944:
* If a <tt>string(…)</tt> variable is designated <tt>bindable</tt>, for instance<lang pascal>var myBindableStringVariable: bindable string(20);</lang>then it is not possible to use the <tt>array</tt>-like substring notation: That means<lang pascal>myBindableStringVariable[firstCharacterIndex .. lastCharacterIndex]</lang>is not permitted since <tt>myBindableStringVariable</tt> is <tt>bindable</tt>.
* It is ''mandatory'' that in <tt>sample[firstCharacterIndex .. lastCharacterIndex]</tt> ''both'' <tt>firstCharacterIndex</tt> and <tt>lastCharacterIndex</tt> are non-descending and denote ''valid indices'' in <tt>sample</tt>. That means both need to be in the range <tt>1 .. length(sample)</tt>. However, for an empty string this range would be empty. Therefore, the array-like substring notation cannot be used for an empty string.
* In <tt>subStr(sample, firstCharacterIndex, substringLength)</tt> the <tt>substringLength</tt> has to be a non-negative integer less than or equal to <tt>length(sample)</tt>. However, <tt>firstCharacterIndex + substringLength ‑ 1</tt> may not exceed <tt>length(sample)</tt>. Therefore, if <tt>sample</tt> is an empty string, the only permissible <tt>firstCharacterIndex</tt> value is <tt>1</tt>&nbsp;(positive one) and the only permissible <tt>substringLength</tt> is <tt>0</tt>&nbsp;(zero). Needless to say how pointless <tt>subStr('&#39;', 1, 0)</tt> is.
* Furthermore, the <tt>totalWidth</tt> specification in <tt>write(myStringOrCharValue:totalWidth)</tt> (and <tt>writeLn</tt>/<tt>writeStr</tt> respectively) has to be greater than or equal to zero. To take advantage of this procedure in a fool-proof manner, you need to extend your width expression like this:<lang pascal>write(sample:pred(length(sample), ord(length(sample) > 0))); { all but last char }</lang>
 
149

edits