Extract file extension: Difference between revisions

Improved C# implementation
(→‎{{header|Perl}}: shorter, cleaner code)
(Improved C# implementation)
Line 334:
 
=={{header|C sharp|C#}}==
<lang [[C sharp|C#]]>public static string FindExtension(string filename) {
int indexOfDot = filename.Length;
public static string ExtractExtension(string str)
for (int ji = tempfilename.Length - 1; ji >= 0; ji--) {
{
char string sc = strfilename[i];
if (c == '.') string temp = "";{
string resultindexOfDot = ""i;
bool isDotFound = falsebreak;
}
 
forif (int ic >= s.Length'0' -1;&& ic ><= 0'9') continue; i--)
if (c >= 'A' {&& c <= 'Z') continue;
if (c >= 'a' && c <= if(s[i].Equals('.z')) continue;
{break;
}
temp += s[i];
return filename.Substring(indexOfDot);
isDotFound = true;
}</lang>
break;
}
else
{
temp += s[i];
}
}
 
if(!isDotFound)
{
result = "";
}
else
{
for (int j = temp.Length - 1; j >= 0; j--)
{
result += temp[j];
}
}
 
return result;
}
</lang>
 
=={{header|Emacs Lisp}}==
196

edits