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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Jan 31, 2011, 10:13 AM EST
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 NairRank #92 · 22.8K reputationPosted Jan 30, 2011, 8:03 PM EST
ShankeyRank #972 · 2.1K reputationPosted Jan 30, 2011, 8:05 PM EST
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.
PankaJ D147 reputationPosted Jan 30, 2011, 8:07 PM EST
Please tell me how can I do this in c#.net
Suthish NairRank #92 · 22.8K reputationPosted Jan 30, 2011, 8:29 PM EST
ShankeyRank #972 · 2.1K reputationPosted Jan 30, 2011, 10:40 PM EST
Use following
Path.GetFileNameWithoutExtension
Suthish NairRank #92 · 22.8K reputationPosted Jan 31, 2011, 8:18 AM EST
Blocked AccountRank #403 · 6.2K reputationPosted Jan 31, 2011, 6:37 PM EST
You can do this by using this code
string FileName = "Image1.jpeg";
FileName = FileName.Substring(0, FileName.LastIndexOf("."));
Purushottam RathoreRank #120 · 18.2K reputationPosted Jan 31, 2011, 6:52 PM EST
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
Sam HobbsRank #107 · 20.5K reputationPosted Jan 31, 2011, 7:26 PM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 1, 2011, 8:00 AM EST
Above already provided a simple solution, its a single line of code..