I have to check the condition in asp.net for string array
The conditions is I can either have two values 360__image.jpg and image.jpg.
I have to return the correct value from the condition
- If the string has 360_image.jpg I have to return only image.jpg and cutting 360_
- If the string is image.jpg I have to return the same image.jpg
Code
public string splitString(string str)
{
string[] FileName = str.Split('_');
if (FileName[2] != "")
{
return FileName[2];
}
else
{
return FileName[0];
}
}
The problem with above code is I am getting the error
Index was outside the bounds of the array