Assign: startIndex cannot be larger than length of string. Parameter name: startIndex

What does it mean ?

It sounds like you’re trying to use the Substring function. The first parameter is StartIndex, which is the 0-based index where you want to start the string. In your case, your index is longer than the length of the string.

Let’s say we have a string “Soudios”.
You can think of the indexes as being between the letters.
0 1 2 3 4 5 6 7
S o u d i o s

Soudios.Substring(3) is equal to “dios”.
Soudios.Substring(0,4) would be “Soud”.

But if I try to do Soudios.Substring(10) it would throw the error that you are getting above because that index is past the bounds of the string. You need to check the variable or value that you are using there.


Ok understand, but the text will change so i need to take everything which is front of client for exemple.

Client : SoudioSoudio here i need SoudioSoudio
Client : Soudio here i need Soudio
Client Daniel here i need Daniel

So how can i do plz ?


fastest way to do it is to split your string by “:” and taking the last part.

Lots of ways to manipulate strings. Substring is one way, but generally not recommended as it is slow and hard to work with.

@LKG mentioned string.Split which is a good way, depending on how the input string is structured. Using his method you would assign ClientName = ClientInformation.Split(":"c)(1).Trim()

Another good method is to use regex. With regex method you would assign ClientName = Regex.Match(ClientInformation,"(?<=Client\s*:\s*)\b\w*").Value.Trim()

this is what i have :
ClientInformation.Substring(Clientinformation.IndexOf("ClientID: ") +“ClientID:”.Length).Split(Environment.NewLine.ToCharArray)(0)

@Soudios why are you using substring in addition to split? Just use one or the other. I posted exact formulas in my post directly above yours that would work for the split method or the regex method.

@DanielMitchell provided a great summary of how substring works if you prefer to use that method instead. You should not mix/match the methods unless there is a specific reason for it, which would be very unusual for substring + split

i am a little confused can you send me the right sentence plz ?

Split method: assign ClientName = ClientInformation.Split(":"c)(1).Trim()

Regex method: assign ClientName = Regex.Match(ClientInformation,"(?<=Client\s*:\s*)\b\w*").Value.Trim()

Don’t really know how it works with your sentence