One: Always detach the file path, name, extension from the string,
Two: Code
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacefilepathstring{ Public Partial classFrm_main:form { PublicFrm_main () {InitializeComponent (); } Private voidBtn_openfile_click (Objectsender, EventArgs e) { if(Openfiledialog1.showdialog () = = DialogResult.OK)//determine if a file is selected { stringP_str_all = Openfiledialog1.filename;//record the selected file full path stringP_str_path =//Get file pathP_str_all. Substring (0, P_str_all. LastIndexOf ("\\") +1);//from the last/start---to the last \ length from the last/start stringP_str_filename =//Get file nameP_str_all. Substring (P_str_all. LastIndexOf ("\\") +1,//from the last/start---to the last one from the last/start. LengthP_str_all. LastIndexOf (".") -(P_str_all. LastIndexOf ("\\")+1)); stringP_str_fileexc =//get file name extensionP_str_all. Substring (P_str_all. LastIndexOf (".") +1,//from the last one. Start----to from the last. Start the last lengthP_str_all. Length-p_str_all. LastIndexOf (".")-1); Lb_filepath. Text="file path:"+ P_str_path;//Show file pathLb_filename. Text ="file name:"+ P_str_filename;//Show file nameLb_fileexc. Text ="file extension:"+ P_str_fileexc;//Show Extensions } } }}
Three: Replace a class of strings,
Four: Code
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacereplacestring{ Public Partial classFrm_main:form { PublicFrm_main () {InitializeComponent (); } Private voidBtn_replace_click (Objectsender, EventArgs e) {Txt_str. Text=//Replace all strings that meet the criteria using the Reaplce method of the string objectTxt_str. Text.replace (Txt_find. Text, Txt_replace. Text); } }}