Search code examples
c#.net-core.net-framework-version

C# Substring return wrong value


var newEncodedFiles = @"C:\Users\wande\OneDrive\Documentos\Visual Studio 2019\Spira\Spira\bin\Debug\netcoreapp5.0\Translated\master\new_uspc\menu\macrodic.dcp";
var newPath = newEncodedFiles.Substring(0, dcpFile.LastIndexOf('.'));

This code returns:

C:\Users\wande\OneDrive\Documentos\Visual Studio 2019\Spira\Spira\bin\Debug\netcoreapp5.0\Translated\master\new_uspc\menu\macro

I am trying to remove file extension to get:

C:\Users\wande\OneDrive\Documentos\Visual Studio 2019\Spira\Spira\bin\Debug\netcoreapp5.0\Translated\master\new_uspc\menu\macrodic

Solution

  • Its working as expected for me in .net core 3.1 console application.

    var newEncodedFiles = @"C:\Users\wande\OneDrive\Documentos\Visual Studio 2019\Spira\Spira\bin\Debug\netcoreapp5.0\Translated\master\new_uspc\menu\macrodic.dcp";
    var newPath = newEncodedFiles.Substring(0, newEncodedFiles.LastIndexOf('.'));
    

    You need to use newEncodedFiles, not dcpFile.