I have an array with items having names with .txt. I want to remove the extension. The following code is not working.
var xx = filenames.ForEach(x => { int fileExtPos = x.LastIndexOf("."); if (fileExtPos >= 0) x = x.Substring(0, fileExtPos); }); Can anyone help what am i doing wrong here?
Thanks
"The following code is not working."-- Why is it not working? Is there an error? Are the results wrong? Also, in the future dont use the.ForEach()extension method. Use aforeachloopfilenamesis an array. Also, do you want the filenames (without extension) to be written back to the array? Or do you want to project that to a new list / array? Or something else?var names = filenames.Select(Path.GetFileNameWithoutExtension);