Extract file extension: Difference between revisions
Content added Content deleted
(→{{header|Perl}}: shorter, cleaner code) |
(Improved C# implementation) |
||
Line 334: | Line 334: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
<lang [[C sharp|C#]]> |
<lang [[C sharp|C#]]>public static string FindExtension(string filename) { |
||
int indexOfDot = filename.Length; |
|||
public static string ExtractExtension(string str) |
|||
⚫ | |||
{ |
|||
char c = filename[i]; |
|||
if (c == '.') { |
|||
indexOfDot = i; |
|||
break; |
|||
⚫ | |||
if (c >= '0' && c <= '9') continue; |
|||
if (c >= 'A' && c <= 'Z') continue; |
|||
if (c >= 'a' && c <= 'z') continue; |
|||
break; |
|||
} |
|||
temp += s[i]; |
|||
return filename.Substring(indexOfDot); |
|||
isDotFound = true; |
|||
⚫ | |||
break; |
|||
} |
|||
else |
|||
{ |
|||
temp += s[i]; |
|||
} |
|||
⚫ | |||
if(!isDotFound) |
|||
{ |
|||
result = ""; |
|||
} |
|||
else |
|||
{ |
|||
⚫ | |||
{ |
|||
result += temp[j]; |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
⚫ | |||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |