Skip to content

Instantly share code, notes, and snippets.

@odenijs
Created July 31, 2013 13:22
Show Gist options
  • Save odenijs/6121921 to your computer and use it in GitHub Desktop.
Save odenijs/6121921 to your computer and use it in GitHub Desktop.
Get the alt text from an image path from it's title with the extension
public static string GetAltTextFromImage(string path)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(path))
{
// Get start position for image name from path
int first = path.LastIndexOf("/") + 1;
// Get last position for image name from path
int last = path.LastIndexOf(".");
result = last > first ? path.Substring(first, last - first) : path;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment