1. Separating the file path, name, and extension from the string,
Ii. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace FilePathString {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private void btn_Openfile_Click (object sender, EventArgs e) {if (openfilealodig1.showdidialog () = DialogResult. OK) // determine whether the file {string P_str_all = openFileDialog1.FileName is selected; // record the full path of the selected file string P_str_path = // obtain the file path P_str_all.Substring (0, p_str_all.LastIndexOf ("\") + 1 ); // start from the last/--- start from the last/the length of the last \ string P_str_filename = // get the file name P_str_all.Substring (P_str_all.LastIndexOf ("\") + 1, // start from the last/--- start from the last. the length of P_str_all.LastIndexOf (". ")-(P_str_all.LastIndexOf (" \ ") + 1); string P_str_fileexc = // get the file extension P_str_all.Substring (P_str_all.LastIndexOf (". ") + 1, // from the last one. start ---- from the last one. start the last length P_str_all.Length-P_str_all.LastIndexOf (". ")-1); lb_filepath.Text =" file path: "+ P_str_path; // display the file path lb_filename.Text =" file name: "+ P_str_filename; // display file name lb_fileexc.Text = "File Extension:" + P_str_fileexc; // display extension }}}}
3. replace a certain type of string,
4. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace ReplaceString {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private void btn_replace_Click (object sender, EventArgs e) {txt_str.Text = // use the Reaplce method of the string object to replace all strings that meet the conditions txt_str.Text.Replace (txt_find.Text, txt_replace.Text );}}}