Extract file extension: Difference between revisions
Added C# implementation using Regex
(Improved C# implementation) |
(Added C# implementation using Regex) |
||
Line 347:
break;
}
//The dot must be followed by at least one other character,
return filename.Substring(indexOfDot);▼
//so if the last character is a dot, return the empty string
▲ return indexOfDot + 1 == filename.Length ? "" : filename.Substring(indexOfDot);
}</lang>
'''Using regular expressions (C# 6)'''
<lang [[C sharp|C#]]>public static string FindExtension(string filename) => Regex.Match(filename, @"\.[A-Za-z0-9]+$").Value;</lang>
=={{header|Emacs Lisp}}==
|