How to sort property -value pair in alphabetical order with Matlab

后端 未结 2 973
名媛妹妹
名媛妹妹 2021-01-22 13:17

I want to add a property-value pair to existing file. In the mean time all the properties should be ordered in alphabetical order. For example :

[Info] % proper         


        
2条回答
  •  [愿得一人]
    2021-01-22 13:49

    Is this a .ini file? You might want to take a look at INIConfig from the MATLAB File Exchange, a set of routines for handling INI files arranged in a convenient class. I haven't used it, but perhaps it might do what you need.

    If not, you can always:

    1. Read in the file
    2. Loop through it line by line
    3. When you find a line starting with [ followed by a word alphabetically later than the property you'd like to insert, insert your property and value
    4. Include the remainder of the file
    5. Write the whole file back out again.

提交回复
热议问题