Index was outside the bounds of array source in Assign

Hi Alll,

I have a variable Name is StrString, type string.

I am using split StrSting= StartString.Trim.Split("-"c)(1).

if value of StrString=“Approved (crawqa - May 14, 2019)” bot is working correct.
if value of StrString= “Previous Assignment To Jon Ansah XactOnline Support (Crawford & Co.) On Oct 4, 2018”

It is showing error= Index was outside the bounds of array source in Assign.

Knidly help me on this .

Kindly help me on this .
Thanks & Regards,
Naim

@Naim

You are splitting the string based on “-”. But in the second String there no “-”. Because of that you are getting that error.

Check that the string contains “-” before splitting. The second example is failing because it doesn’t have a hyphen character so the Split returns an array with only one item. So the index 1 is out of bounds.

Thanks for your response…
the both value is coming from data table so it may be change accordingly

Kindly suggest…

Regards,
Naim

Kindly suggest what should I can do in this case…
Regards,
Naim

You need to check that the String contains “-”. Use an If and for the condition do StrString.Contains("-"). Then if true you can split and do your normal logic. If false you need to process the string differently.

thanks for the reply I want to skip If it not contains("-") please advise…

@Naim

Ok. But actually what are you trying to fetch from both the strings ?

Date month and year only…

@Naim

Before dividing into String using split function first check whether the string contains “-” or not. If it contains then split it based in “-” else don’t split it.

@Naim To get Date month and year only use regex like this

Hi i have same problem but,
There is a text I’m splitting it when it has 2 index’s but, sometime only 1 index is available then it throws Index was outside the bounds of the array.

for Example strExample=“Hospital Name 1-203659045”

I need to Split this and update into different columns
Please help me when it doesn’t have phone number need to ignore the phone number column

@Krupa_P1

First check whether string contains of hypen “-” or not in Input string.

If strExample.Contains("-")
Then
Use Split function to split the string
Else
No Split