The multiple lines of text saved in single file format to read and write ini


ddd[3]


/*

* [info]

* group = a,b,c,d

*

* Ini needs modifying group configuration information value

*

* 1: Adds value to a group of

Remove * 2: removing a value from the value in the group

*

*

* 1 reads the value in the group, it is converted into a string array,

* Remove all blank lines, re-add the array to a list, add the behavior is not empty

* Add: To add value to the list

* Convert list of strings in a row, with all good apart between lines

*

*

* 2 reads the value of the group, it is converted into a string array,

* Remove all blank lines, re-add the array to a list, add the behavior is not empty

* Delete: Is there a value judgment to delete the list, there would be deleted, which did not operate

* Convert list of strings in a row, with all good apart between lines

*

* December 26, 2019 22:26:43

*/



        / * 
         * [Info] 
         * = group A, B, C, D 
         * 
         * value needs modifying group configuration information ini 
         * 
         * 1: Adds value to a group of 
         * 2 is removed: remove a group from the value of value 
         * 
         * 
         * 1 reads the value in the group, it is converted into a string array, 
         * remove any blank line back to the array is added to a list is empty is not added 
         * Add: value to be added list 
         * the list into a string line, between lines are well separated by 
         * 
         * 
         * 2 reads the value of the group, it is converted into a string array, 
         * remove all empty rows, the array re-added to a list, the behavior is not empty Add 
         * delete: to determine whether there is value to be deleted list, there would be deleted, which did not operate 
         * convert between all the list into a string, row to row row well separated 
         * 
         *
         * /

         I = 0; I <arr.Length ; i++)// read lines of text to a list 
        /// <Summary> 
        /// AAA, DFD, HHH ,, FF, Hello -> delete list converted into blank lines 
        /// </ Summary> 
        /// <param name = "text"> AAA, DFD, HHH ,, FF, Hello </ param> 
        /// <Returns> </ Returns> 
        Private List < String > the ReadString ( String text) { 
            List < String > LST = new new List < String > ();
             text line to read the list // 
            String [] = ARR text.Split ( ',');
             IF (arr.length> 0) 
            { 
                lst.Clear (); for ( int 
                { String
                
                    ARR = S [I] .trim ();
                     IF (s.Length> 0)      // // add a blank line does not remove all of the empty lines 
                        lst.Add (S); 
                } 
            } the else 
            { 
                lst.Add (text ); 
            } return LST; 
        } /// <Summary> /// /// </ Summary> /// <param name = "resString"> AAA, DFD, HHH ,, FF, the source string Hello </ param > /// <param name = "AddString"> to add the string </ param> public string the AddString ( string resString, string AddString) {
             // read lines of text to a list // [add] // save
            
            


        
        
        
        
        
         
            
            
            List<string> list = ReadString(resString);
            string findString = addString.Trim();
            if (list.IndexOf(findString) ==-1)
            {
                list.Add(findString);
            }

            //转换成一行文本
            resString = string.Join(",", list.ToArray());
            if (resString.EndsWith(","))
                resString = resString.Substring(0, resString.Length - 1);
            return resString;
        }

        public string RemoveString(stringresString,String findString) {
             text lines to read the list // 
            // [Delete] 
            // save 

            IF (resString.Contains ( " , ")) 
            { 
                findString findString.Trim = (); 
                List < String > = the ReadString List (resString) ;
                 IF (list.IndexOf (findString) = -1!) // exists 
                { 
                    list.Remove (findString); 
                } // convert a row of text 
                resString = String .join ( " , ", List.toArray ());
                 IF (resString.EndsWith ( " , "))
                
                    resString = resString.Substring(0, resString.Length - 1);
                return resString;
            }
            else
            {
                return resString.Replace(findString, "");
            }
        }

        private void button删除_Click(object sender, EventArgs e) {
            textBox1.Text = RemoveString(textBox1.Text, textBox2.Text);
        }

        private void button添加_Click(object sender, EventArgs e) {
            textBox1.Text = AddString(textBox1.Text, textBox2.Text);
        }

Guess you like

Origin www.cnblogs.com/xe2011/p/12104815.html