# Take out text from middle of string

**URL:** <https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334>\
**Category:** Uncategorized\
**Created:** [July 30, 2004, 11:04am UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334 "2004-07-30T11:04:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enidea](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Enidea](https://forum.kirupa.com/u/Enidea)\
**Post date:** [July 30, 2004, 11:04am UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/1 "2004-07-30T11:04:18Z")

</div>

Is there a way to take out a part of the text in a string?

like start 7 characters inti the string and end 2 from the end of string

something like:

string=“hello how are you today?”;  
so when done weare done with it the things left in the text is:  
“how are you toda”

sorry if im bad at explaning but my english isnt very good.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 1:57pm UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/2 "2004-07-30T13:57:53Z")

</div>

Use indexAt to get the position of a character, or write a parser that looks for an entire word, then use substring to get a portion of the string.

Or if you already know the position of your text use:

```auto
teststring = "hello how are you today?";
 middle = teststring.substr(6, teststring.length-1);
 trace(middle);

```

Note that the 7th character is numbered 6, an array or string starts at 0, not at 1. That means the 2nd from the end is the total length of the string minus 1, not 2.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 2:51pm UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/3 "2004-07-30T14:51:19Z")

</div>

> [@Mediamonkey](#):
>
> Note that the 7th character is numbered 6, an array or string starts at 0, not at 1. That means the 2nd from the end is the total length of the string minus 1, not 2.

Actually, what this does is take the substring up to _and including_ the 2nd character from the end. As I understand it, you actually want to remove the 2nd character from the end as well (the substring up to and including the 3rd character from the end). For this you would use “testString.length - 2”. Hope that made sense! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 9:05am UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/4 "2004-07-31T09:05:11Z")

</div>

For some reason its not working. I can get away the first part but not the thngs at the end  
teststring=teststring.substr(9, teststring.length-1);

I get teststring from a textfile and its value is:

txt0=“22.9.2004”

I want o take out this part:  
22.9.2004

but I get:  
22.9.2004"

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 11:36am UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/5 "2004-07-31T11:36:14Z")

</div>

> [@Enidea](#):
>
> For some reason its not working. I can get away the first part but not the thngs at the end  
> teststring=teststring.substr(9, teststring.length-1);
> 
> I get teststring from a textfile and its value is:
> 
> txt0=“22.9.2004”
> 
> I want o take out this part:  
> 22.9.2004
> 
> but I get:  
> 22.9.2004"

I`m not sure exactly what you are trying to do but i think there has been some confusion between substr() and substring()  
try  
teststring = “hello how are you today?”;  
myvar = teststring.length-2;  
middle = teststring.substring(6, myvar);  
trace(middle);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 1, 2004, 10:42am UTC](https://forum.kirupa.com/t/take-out-text-from-middle-of-string/59334/6 "2004-08-01T10:42:38Z")

</div>

Got it to work now, had to take -10 because I used same variable as I created.
