Skip to content

Instantly share code, notes, and snippets.

@iGlitch
Created February 4, 2017 16:26
Show Gist options
  • Save iGlitch/fd522346d409379e4b640508008478b9 to your computer and use it in GitHub Desktop.
Save iGlitch/fd522346d409379e4b640508008478b9 to your computer and use it in GitHub Desktop.
Edit .properties files
/**
Property P = new Property();
P.setFileRoute(ROUTE); --add the path to file
P.setProperty(VALUE, KEY); --add a property value/name and its value to the file, or if it doesn´t exist, it´ll create a new one with these elements.
P.getPropertyValue(LINE); --get the value or the key of a line chosen from the file
P.getPropertyKey(LINE);
**/
using System;
using System.IO;
namespace NAMESPACE
{
public class Property
{
private string Value, Key, Route;
private int PropertyLine;
public void setFileRoute(string Route)
{
this.Route = Route;
}
public void setProperty(string Value, string Key)
{
this.Value = Value;
this.Key = Key;
System.IO.StreamReader FL = new System.IO.StreamReader(Route);
string FULL = FL.ReadToEnd();
FL.Close();
StreamWriter SW = new StreamWriter(Route);
SW.WriteLine('\n'+FULL+'\n'+Value+"="+Key);
SW.Close();
}
public string getPropertyKey(int PropertyLine)
{
this.PropertyLine = PropertyLine;
System.IO.StreamReader FL = new System.IO.StreamReader(Route);
string FULL = FL.ReadToEnd();
var SPL1 = FULL.Split('\n');
string LINE = SPL1[PropertyLine];
var SPL2 = LINE.Split('=');
string KEY = SPL2[0];
FL.Close();
return KEY;
}
public string getPropertyValue(int PropertyLine)
{
this.PropertyLine = PropertyLine;
System.IO.StreamReader FL = new System.IO.StreamReader(Route);
string FULL = FL.ReadToEnd();
var SPL1 = FULL.Split('\n');
string LINE = SPL1[PropertyLine];
var SPL2 = LINE.Split('=');
string VALUE = SPL2[1];
FL.Close();
return VALUE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment