String.Substring is failing

Hi All, I’m anticipating a project and just preparing some nodes for when the architect gives me the drawing list, I should be able to prepare the drawing sheets in a snap. On this scenario, I would probably have a single line of text that contains the drawing number: AABB01 (01 as running number) the sheet name: Ground Floor Plan (and so fort). I used the the String.Substring to count the string index to separate them but somehow the second node is giving me an error.

Error: Warning: String.Substring operation failed.
Index and length must refer to a location within the string.
Parameter name: length

Anyone knows what’s happening here? Thanks!

This error is saying that the inouts for the start and end of your Substring don’t fall within the scope of the Substring.

A good way to think of this is with a portion of a deck of cards.

Take out all the cards of a given suit (ie: the hearts), and arrange them in order from lowest to highest.

You should have a collection of 13 cards, which we will consider our string, where each card is a letter.

What your code is doing is counting how many characters there are (in our example 13). It’s then going to the 9th card (discarding everything before that, so 2-10 are tossed), and then trying to take the next 13 cards. So starting with the jack, then the queen, king, and ace… but you’re telling the computer to take 9 more cards and there aren’t any left.

Instead of taking the full count, take the full count less the number you are discarding at the front, by subtracting the starting index from the count.

1 Like

got it. the

length

should be length of the string

startindex

, not the index of the last character of the string. Thanks!

1 Like