Does substring only starts with 0?

activities

#1

I am using a substring to get last words from the text.
variable.substring(68, variable.length)
error is index is out of range , index and length must refer to a location within the string
Does substring need to necessarily start with 0?

Thank you xoxo


#2

No if it will start from 0 this will defeat the purpose of method, can you attach a screenshot or test string/substring? Your formula should be like this Variable.SubString(StartIndex,EndIndex-StartIndex)


#3

@sangasangasanga If u want all text after 68 indexNo. Use Below condition

variable.substring(68)

If u want certain number of number letters from 68 indexNo. Use Below condition
variable.substring(68, number)
where number is number of characters u required from 68 position

What happening in ur case is
variable.substring(68, variable.length)

Ex. ur variable contains 80 letters, ur give starting index as 68, variable.length gives u 80.

From 68 it cant copy 80 characters, since total length of string is 80 itself. So give number of characters u required in that place, otherwise remove that field.


#4

Try to use this:

variable.substring(68, variable.lenght - 68)
or variable.substring(68) - output will be the same as above


#5

length - 1 will work fine