Take out text from middle of string

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.

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:

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

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! :slight_smile:

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:


I want o take out this part:

but I get:

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

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