Created
May 11, 2018 13:44
-
-
Save nbuss848/332471c21f91a09f883c44935c8829bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ParseReportName(string reportName) | |
{ | |
string Result = String.Empty; | |
// Example: '$My Report Name : week ending $d-1' | |
// $d-1 = get todays date and subtract one and format it into MM/dd/yyyy | |
if(reportName.Contains("$")) | |
{ | |
string formula = String.Empty; | |
string type = String.Empty; // d = date is the only supported type atm | |
// $ marks the start of the formula | |
for (int i = reportName.IndexOf('$') + 1; i < reportName.Length; i++) | |
{ | |
if(reportName[i] == '\"') | |
{ | |
continue; | |
} | |
formula += reportName[i]; | |
} | |
type = formula[0].ToString(); | |
if(type == "d") | |
{ | |
DateTime today = DateTime.Today; | |
char Operator = formula[1]; | |
string [] split = formula.Split(new char[] { '+', '-' },StringSplitOptions.RemoveEmptyEntries); | |
int number = Convert.ToInt32(split[1]); | |
reportName = reportName.Substring(0, reportName.IndexOf('$')).Trim(); | |
if (Operator == '+') Result = reportName + " " + (today.AddDays(number).ToString("MM/dd/yyyy")); | |
if (Operator == '-') Result = reportName + " " + (today.AddDays(-number).ToString("MM/dd/yyyy")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment