Extract file extension
Write a program that takes one string argument. The string argument has a extension in the end but it is unknown what extension it is. It can be whatever but going from tail to head the extension is marked by a dot (.). Example:
Template:Extract file extension is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Extract file extension is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
picture.jpg returns .jpg
http://mywebsite.com/picture/image.png returns .png
myuniquefile.longextension returns .longextension
IAmAFileWithoutExtension return an empty string ""
C#
<lang C#> public static string ExtractExtension(string str) {
string s = str; string temp = ""; string result = ""; bool isDotFound = false;
for (int i = s.Length -1; i >= 0; i--) { if(s[i].Equals('.')) { temp += s[i]; isDotFound = true; break; } else { temp += s[i]; } }
if(!isDotFound) { result = ""; } else { for (int j = temp.Length - 1; j >= 0; j--) { result += temp[j]; } }
return result;
} </lang>