Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 791551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:51:19+00:00 2026-05-14T21:51:19+00:00

I am having a strange problem and I can’t seem to figure it out.

  • 0

I am having a strange problem and I can’t seem to figure it out.

My filename is something like this:
DER 1513016-3.020F.NCF.

I want to be able to change it to:
DER 1513016-3.020H.NCF

Sometimes the filename can be this as well:
DER 1513016-3.020F_NEW.NCF

which would change to:
DER 1513016-3.020H_NEW.NCF

This is my code to do this:

OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open";
fDialog.Filter = "NCF files (*.ncf)|*.ncf|All files (*.*)|*.*";
fDialog.InitialDirectory = "C:\\Program Files";
if (fDialog.ShowDialog() == DialogResult.OK)
{
    string newfilename;
    string fileext = Path.GetExtension(fDialog.FileName);

    newfilename = Regex.Replace(fDialog.FileName, "F.NCF", "H.NCF");
    newfilename = Regex.Replace(fDialog.FileName, "F_NEW.NCF", "H_NEW.NCF");
} 

This is where things get weird. The way the code works now, it will NOT change the filename to DER 1513016-3.020H.NCF

If I comment out this line of code:

//newfilename = Regex.Replace(fDialog.FileName, "F_NEW.NCF", "H_NEW.NCF");

it will work fine and the file will now become: DER 1513016-3.020H.NCF

However, if I uncomment that line of code, the filename will not change to DER 1513016-3.020H.NCF. It will stay as DER 1513016-3.020F.NCF.

Why is that line of code causing the routine to not change the filename?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:51:20+00:00Added an answer on May 14, 2026 at 9:51 pm

    Use newfilename instead of fDialog.FileName on the second call or the return value of the first one will never be used.

    PS: You can use String.Replace instead of Regex.Replace since you’re not using any regular expressions. Plus, the dot means “any character” in a regex so you should consider escaping it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be having a strange problem which I can't fully understand. This
I'm having a strange problem that I can't work out and wonder if anybody
I'm having a strange problem which I cannot figure out for the life of
I'm having a strange problem where I can't seem to set the initial value
I am having a strange problem, maybe something to do with Apache more than
I am having a strange problem, maybe you can help: I'm trying to convert
I'm having a strange problem here, and I can't manage to find a good
I am having a strange problem while returning a string. it says can not
I'm having this strange problem with codeigniters flashdata in my login form. When I
I'm having a strange problem where a user can enter the following text Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.