Length cannot be less than zero error in assign activity, Client hash assignment

ClientInfo.Substring(ClientInfo.IndexOf(“Client ID:”)+11, ClientInfo.IndexOf(“Client Name:”) - ClientInfo.IndexOf(“Client ID:”)+11)) this is the string i have passed in assign activity. Can anyone please help me to find out the issue!!


1 - ClientInfo.Replace(“Client ID:”, “-”).Trim() (do the same for others…)

2 - Then Split the values by “-” just like: test = ClientInfo.Split("-"c)

You will get test(0) the ID test(1) the name…


am getting output like this

Replace all the labels:
ClientInfo.Replace(“Client ID:”, “”).Trim()
ClientInfo.Replace(“Client Name:”, “”).Trim()
ClientInfo.Replace(“Client Country:”, “”).Trim()

Then Split by: test = ClientInfo.Split(":"c)

Have replaced the Trim labels with above three. Where i have to use split activity? After these i need to split for each one with assign activity?

Hi @Anju_Sekharan,

Here you are using a simple .net function Substring which will get you string from starting index upto definite length.

(i.e.) Result= inputString.Substring(startingIndex,lengthofString)


Consider you are having an input string ‘This is a sample text’, from this you need to get only ‘a sample text’. Then below will be the code to extract.

Result = inputString.Substring(8,13)

Then if you want to get only ‘This’.

Result = inputstring.Substring(0,4)

Hence if you give a index that does not exists in sting or the length of string less than 0 error will occur.

In you case ‘ClientInfo.Substring(ClientInfo.IndexOf(“Client ID:”)+11, ClientInfo.IndexOf(“Client Name:”) - ClientInfo.IndexOf(“Client ID:”)+11))’

Bolded part is the length argument part in function, which is actually returning 0 that why you are getting this error.


Replace then make the Split u will get the ID on position 0 name on position 1 and country on position 2 ex: test(0) will return the ID

1 Like

Yes have used split function.got output like this;Capture34
ClientInfo = ClientInfo.Split(";“c)(0)
then i have used ClientInfo(0)

but when extracting clientid from this string, shows emptyCapture35

1 Like

Don’t Split by ; use : and replace all the static Strings Client ID, Client Name and Client Country

1 Like

Still am getting the same output!!

Get value on position 1

System1_ExtractClientInformation.xaml (11.5 KB)

If i am using : instead of ; the output shows Client ID alone

I don’t know if you have tried but try to use “write line” for each of the variables before displaying the log message. You could do so for the whole string variable and/or just to display the length of the variable. You should then have indications where something might be wrong and continue diving deeper to get to the root cause of the issue. That’s how I usually try to solve these things, but others on this forum are more experienced than I am :slight_smile:.

Good luck, hope it gives you something to try.


Use below one:

Client ID: ClientInfo.Substring(Client.IndexOf("Client ID: ")+"Client
ID: ".Length).Split(Environment.NewLine.ToCharArray)(0)

And same way try for other two also. If you have any doubts then let me know.

1 Like

Yes i have issues. getting output correctly while running seperately. But while executing main file, i got error like, “start index cannot be larger than length of string”

This is a helpful and simple solution. Nice.:+1:

1 Like