Advertisement
nateshoffner

Untitled

Oct 23rd, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1.         private const char CommentDelimiter = ';';
  2.  
  3.         [DllImport("kernel32")]
  4.         private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
  5.  
  6.         [DllImport("kernel32")]
  7.         private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
  8.  
  9.         public static void IniWriteValue(string filePath, string section, string key, string value, string comment)
  10.         {
  11.             var str = string.Format(" {0}", value);
  12.             if (comment != null) str += string.Format(" {0} {1} ", CommentDelimiter, comment);
  13.             WritePrivateProfileString(section, key, str, filePath);
  14.         }
  15.  
  16.         public static string IniReadValue(string filePath, string section, string key)
  17.         {
  18.             var temp = new StringBuilder(255);
  19.             GetPrivateProfileString(section, key, "", temp, 255, filePath);
  20.             return temp.ToString().Split(CommentDelimiter)[0].Trim();
  21.         }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement