# Find a subtext between two positions in a larger text, after assigning variables to the first and last points

**URL:** <https://discourse.julialang.org/t/find-a-subtext-between-two-positions-in-a-larger-text-after-assigning-variables-to-the-first-and-last-points/38614>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 2, 2020, 3:59pm UTC](https://discourse.julialang.org/t/find-a-subtext-between-two-positions-in-a-larger-text-after-assigning-variables-to-the-first-and-last-points/38614 "2020-05-02T15:59:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [May 2, 2020, 3:59pm UTC](https://discourse.julialang.org/t/find-a-subtext-between-two-positions-in-a-larger-text-after-assigning-variables-to-the-first-and-last-points/38614/1 "2020-05-02T15:59:27Z")

</div>

In continuation to this question ([link](https://discourse.julialang.org/t/find-the-location-s-of-all-occurrences-of-a-specific-string-in-txt/38578)), I am trying to find the subtext between two points in a larger text (target).

When I write:

```
target[2735:2738]

```

I get the correct answer “1.32”

However, when I instead assign the start id (2735) to a variable, and do the same for the last id (2738) and write:

```
target[firstid:lastid)

```

I get an error (see the image for complete details):

 ![firstid_lastid](https://global.discourse-cdn.com/julialang/original/3X/1/f/1f586942389b310119a0439a4339b38739ed76e6.jpeg)

What is the correct procedure?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 2, 2020, 4:09pm UTC](https://discourse.julialang.org/t/find-a-subtext-between-two-positions-in-a-larger-text-after-assigning-variables-to-the-first-and-last-points/38614/2 "2020-05-02T16:09:37Z")

</div>

Try `target[firstid:lastid]` instead of `target[firstid:lastid)`, as the error message suggests.

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [May 2, 2020, 4:16pm UTC](https://discourse.julialang.org/t/find-a-subtext-between-two-positions-in-a-larger-text-after-assigning-variables-to-the-first-and-last-points/38614/3 "2020-05-02T16:16:19Z")

</div>

> [@pfitzseb](#):
>
> target[firstid:lastid]

Oh, that’s embarrassing.
