# Reference Manual, Expressions

**URL:** <https://forum.vassalengine.org/t/reference-manual-expressions/75483>\
**Category:** Technical Support & Bugs\
**Created:** [September 18, 2022, 3:16am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483 "2022-09-18T03:16:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [September 18, 2022, 3:16am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/1 "2022-09-18T03:16:10Z")

</div>

The description for usage of the substring(start, end) is slightly incorrect. Currently states:  
**substring(start,end)** returns the substring from _start_ to _end_ , exclusive.  
The _exclusive_ applies only to the _start_. The _end_ is really the length to truncate at.  
For example - using abcdefgh as the string, the start as 0 and the end as 5 the expression will return abcde (5 characters). If the term _exclusive_ was applied then the returned string would be abcd.  
Just thought I’d bring this up.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [September 18, 2022, 3:42pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/2 "2022-09-18T15:42:20Z")

</div>

The description is accurate as-is. Whenever you have a range in computer science, it’s customary to indicate whether the right end is inclusive or exclusive. It’s extraordinarily unusual for the left end to be anything other than inclusive, so that’s omitted.

---

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [September 18, 2022, 4:23pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/3 "2022-09-18T16:23:36Z")

</div>

How many users ‘have a range in computer science’? I’m an electronics engineer. Been an engineer I like things to be specific, not implied. Besides that, your right and left ends are transposed. Last I looked abcde has the a on the left or start and the e is on the right or end. Call me anal retentive because that is what I am.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [September 18, 2022, 4:28pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/4 "2022-09-18T16:28:57Z")

</div>

I still don’t see what’s wrong with the description. `substring(start,end)` is supposed to return the range `[start,end)`, which in words is “from start to end, exclusive”.

Please give a specific example showing how the behavior doesn’t match the description.

---

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [September 19, 2022, 10:57am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/5 "2022-09-19T10:57:52Z")

</div>

see 1st post. I would word that particular phrase _from start (exclusive) to end_  
I would probably also consider a note when using the substring functions - check the length before using substring to ensure the target string is long enough. Otherwise there will be an error.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [September 19, 2022, 10:59am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/6 "2022-09-19T10:59:38Z")

</div>

> [@palad0n](#):
>
> I would word that particular phrase _from start (exclusive) to end_

Sorry, I sill don’t understand what you’re saying. Noting the start as exclusive would be incorrect. The start is supposed to be inclusive.

---

<div class="post-metadata">

**Author:** ![pawnpusher](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/pawnpusher/32/184_2.png) [@pawnpusher](https://forum.vassalengine.org/u/pawnpusher)\
**Post date:** [September 19, 2022, 12:19pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/7 "2022-09-19T12:19:57Z")

</div>

Is the first character in a string character 0?

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [September 19, 2022, 1:21pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/8 "2022-09-19T13:21:21Z")

</div>

Yes, everything, strings included, is indexed from zero.

---

<div class="post-metadata">

**Author:** ![pawnpusher](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/pawnpusher/32/184_2.png) [@pawnpusher](https://forum.vassalengine.org/u/pawnpusher)\
**Post date:** [September 19, 2022, 2:46pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/9 "2022-09-19T14:46:38Z")

</div>

So in example by @palad0n

> [@palad0n](#):
>
> For example - using abcdefgh as the string, the start as 0 and the end as 5 the expression will return abcde (5 characters)

The returned string “abcde” are characters 0 through 4 of “abcdefgh”. So the end, character 5, the “f”, is excluded.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [September 19, 2022, 3:01pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/10 "2022-09-19T15:01:29Z")

</div>

> [@pawnpusher](#):
>
> So the end, character 5, the “f”, is excluded.

Yes, the range `[0,5)` consists of the first five characters of the string. The character at position 5 is excluded, due to the range being open to the right (i.e., exclusive). This is as intended and matches the documentation.

---

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [September 19, 2022, 4:45pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/11 "2022-09-19T16:45:27Z")

</div>

Thank you. Some other research clarifies this further. Strings start at the first been 0. I believed that the first of a string would be 1. To me that is logical. Using 0 as the first character of a string is not logical, but that seems to be way this java stuff works. Go figure.  
Remember that 0 was not even a number for ages.

---

<div class="post-metadata">

**Author:** ![JoelCFC25](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/joelcfc25/32/2687_2.png) [@JoelCFC25](https://forum.vassalengine.org/u/JoelCFC25)\
**Post date:** [September 19, 2022, 5:53pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/12 "2022-09-19T17:53:44Z")

</div>

> [@palad0n](#):
>
> Using 0 as the first character of a string is not logical, but that seems to be way this java stuff works. Go figure.

It’s far from alone–I daresay [nearly all of the heavily-used languages for software development are zero-indexed](https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Array_system_cross-reference_list). Of those that aren’t, they’re either very antiquated or highly-specialized, e.g. for math/statistical packages.

---

<div class="post-metadata">

**Author:** ![pawnpusher](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/pawnpusher/32/184_2.png) [@pawnpusher](https://forum.vassalengine.org/u/pawnpusher)\
**Post date:** [September 19, 2022, 8:08pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/13 "2022-09-19T20:08:15Z")

</div>

> [@JoelCFC25](#):
>
> > [@palad0n](#):
> >
> > Using 0 as the first character of a string is not logical, but that seems to be way this java stuff works. Go figure.
> 
> It’s far from alone–I daresay [nearly all of the heavily-used languages for software development are zero-indexed](https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Array_system_cross-reference_list). Of those that aren’t, they’re either very antiquated or highly-specialized, e.g. for math/statistical packages.

As an engineer that cut his programming “software” teeth on FORTRAN in the late 1970s, I’m more familiar with the idea of the index starting at 1 rather than 0. I guess FORTRAN is now considered antiquated.

---

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [September 20, 2022, 1:16pm UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/14 "2022-09-20T13:16:31Z")

</div>

Yes indeed. Fortran IV. Mainframe RMIT using punch cards. Made a small mistake with do loop, must have hit the 0 key many times. Loop went for 100,000 times. Huge, at the time, CPU usage.

---

<div class="post-metadata">

**Author:** ![jmichael](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@jmichael](https://forum.vassalengine.org/u/jmichael)\
**Post date:** [September 21, 2022, 1:21am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/15 "2022-09-21T01:21:24Z")

</div>

I wish the go to example would not start at 0. (Or 1.)

I usually need to check whether “substring” is given “start,end” or “start,length”. And whether “end” is really “first character _not_ returned”.

---

<div class="post-metadata">

**Author:** ![pawnpusher](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/pawnpusher/32/184_2.png) [@pawnpusher](https://forum.vassalengine.org/u/pawnpusher)\
**Post date:** [September 21, 2022, 2:25am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/16 "2022-09-21T02:25:49Z")

</div>

So how about the string alphabet = “abcdefghijklmnopqrstuvwxyz”  
So I’m thinking alphabet.substring(3,7) would be “defg”

---

<div class="post-metadata">

**Author:** ![jrwatts](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/jrwatts/32/6972_2.png) [@jrwatts](https://forum.vassalengine.org/u/jrwatts)\
**Post date:** [September 21, 2022, 5:48am UTC](https://forum.vassalengine.org/t/reference-manual-expressions/75483/17 "2022-09-21T05:48:49Z")

</div>

That would be correct.
