开发者

how to cut the string at the time of update in gridview?

开发者 https://www.devze.com 2023-03-07 09:53 出处:网络
I m displaying the image file in gridview. At time of update I want to show only the file name to update and not the extension.

I m displaying the image file in gridview. At time of update I want to show only the file name to update and not the extension. like file1.jpg 开发者_如何学JAVAis there but i should only change file1 and not .jpg how to do that?


You can use the Path API as follow

var fileName = System.IO.Path.GetFileNameWithoutExtension(*filePath*);


Try this

string filename = "file1.jpg";
string filenameonly=filename.Substring(0,filename.LastIndexOf('.'));


Here's a sample:

var fName = "test.1.jpg";
var noExt = fName.Remove(fName.LastIndexOf('.'), fName.Length - fName.LastIndexOf('.'));
Console.WriteLine(noExt);

The noExt variable contains the string you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消