public String fixalt(String text) { Regex reg = new Regex(@"]+>"); MatchCollection matches = reg.Matches(text); String src, match; for (int i = 0; i < matches.Count; i++) { match = matches[i].ToString(); if (match.IndexOf("alt=") < 0) { // Use the src info to try to come up with an alt tag that makes sense. if (match.IndexOf("src=") >= 0) { // get everything after the src tag src = match.Substring(match.IndexOf("src=") + 4); // strip out all quotes src = src.Replace("\"", "").Replace("'", ""); // end at the first space src = src.Substring(0, src.IndexOf(" ")); // grab everything after the last / (don't use path info for the image, just try to get the image name) if (src.IndexOf("/") >= 0) { src = src.Substring(src.LastIndexOf("/")+1); } src = src.Replace(".jpg", "").Replace(".png", "").Replace(".gif", "").Replace("_", " ").Replace("+", " ").Replace("-", " "); text = text.Replace(match, match.Substring(0, match.LastIndexOf(" ")) + " alt=\"" + src + "\" />"); } else { text = text.Replace(match, match.Substring(0, match.Length - 1) + " alt=\"contentimage\">"); } } } return text; }