I have store Image name in database with its extension,like image1.jpg
Now I want to get only the name of Image without extension.
like image1
how Can I do this?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mahesh ChandPosted Jan 31, 2011, 3:13 PM
private void FileNameWithoutExtn()
}{
String fimeName = "Image1.jpg";
char[] findChars = new char[] { '.'};
int idx = fimeName.IndexOfAny(findChars);
string justFileName = fimeName.Substring(0, idx);
Console.WriteLine(justFileName);
Suthish NairPosted Feb 1, 2011, 1:00 PM
Above already provided a simple solution, its a single line of code..
Console.WriteLine(System.IO.Path.GetFileNameWithoutExtension("Image1.jpg"));
Sam HobbsPosted Feb 1, 2011, 12:26 AM
Purushottam RathorePosted Jan 31, 2011, 11:52 PM
String imgFullname="image1.jpg"
string imagename=imgFullname.Remove(imgFullname.LastIndexOf('.'));
For more detail please try this.
http://www.dotnetheaven.com/UploadFile/prathore/BreakString09142009082617AM/BreakString.aspx
Thanks
Blocked AccountPosted Jan 31, 2011, 11:37 PM
You can do this by using this code
string FileName = "Image1.jpeg";
FileName = FileName.Substring(0, FileName.LastIndexOf("."));
Suthish NairPosted Jan 31, 2011, 1:18 PM
ShankeyPosted Jan 31, 2011, 3:40 AM
Use following
Path.GetFileNameWithoutExtension
Suthish NairPosted Jan 31, 2011, 1:29 AM
PankaJ DPosted Jan 31, 2011, 1:07 AM
Please tell me how can I do this in c#.net
ShankeyPosted Jan 31, 2011, 1:05 AM
Following is simple and easy one,
select SUBSTRING('image1.jpg',CHARINDEX('.','image1.jpg' )+1,LEN('image1.jpg') - CHARINDEX('.','image1.jpg' ))
replace 'image.jpg' with your column name.
Suthish NairPosted Jan 31, 2011, 1:03 AM