How can i get the string "tulip" from the string "tulip.jpg" using Split function in c#?
string str = "tulip.jpg";
I store the result "tulip" in str1(string type valiable).
How can i get the string "tulip" from the string "tulip.jpg" using Split function in c#?
string str = "tulip.jpg";
I store the result "tulip" in str1(string type valiable).
That's a filename, so i wouldn't use String.Split
but the Path
-methods:
string fileNameOnly = Path.GetFileNameWithoutExtension("tulip.jpg");
For what it's worth: fileNameOnly = "tulip.jpg".Split('.')[0];
This will be a problem if the name also contains dots.
So if you insist on string methods String.Substring
or String.Remove
would be better:
fileNameOnly = fileName.Remove(fileName.LastIndexOf('.'));