开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜