I can written an application which converts strings (made of numbers) from 8 - 12 characters in length (see examples below)
1404336133
4174728823
0587035281
Basically I want to convert the strings above into a specific format (stored in a config file) for the time being its as shown below.
<add key="Consumer_Code_Format_For_Code_Length_Eight" value="#### ####"/>
<add key="Consumer_Code_Format_For_Code_Length_Nine" value="### ### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Ten" value="### #### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Eleven" value="#### ### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Twelve" value="#### #### ####"/>
I am currently using the following code to format the codes ...
public static string FormatCode(string code)
{
switch (code.Length.ToString())
{
case "8":
string codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
case "9":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Nine"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
case "10":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Ten"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
case "11":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eleven"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
case "12":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Twelve"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
default:
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
break;
}
// Finally return the newly formatted code
return code;
}
However, for the code 0587035281 it displays "58 7035 281" therefore removing the leading zero which I require.
Any ideas how to stop this and also is there anything wrong or suspicious with my code?
Looking forward to your reply
public static string FormatCode(string code)
{
switch (code.Length.ToString())
{
case "8":
string codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
break;
case "9":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Nine"];
break;
case "10":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Ten"];
break;
case "11":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eleven"];
break;
case "12":
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Twelve"];
break;
default:
codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
break;
}
char[] result = new char[codeformat.Length];
int used = 0;
for(i = 0; i < codeformat.Length; i++)
{
if (codeformat[i] == '#')
{
result[i] = code[used];
used++;
}
else
result[i] = codeformat[i];
}
// Finally return the newly formatted code
return new string(result);
}
Doublevalues are actually stored as numbers, so leading zeroes are being automatically removed when using Double.Parse().
Tho add the nleading zeroes once again, you can do something similar to this (not tested, written from the top of my head.) Remember the original length, then compare the result and add as many leading zeroes as required.
public static string FormatCode(string code)
{
int originalLength = code.Length;
switch (originalLength)
{
case 8:
string codeFormat = ...;
code = ...;
break;
case 9:
codeFormat = ...;
code = ...;
break;
// ...
while (code.Length < originalLength) {
code = "0" + code;
}
return code;
}
There's no pretty solution you can do inline, you'll have to do your own processing. Since this is not really a number you're dealing with, and maybe you may need to have some non-numeric literals there, best that you just insert a space every N characters. This would go something like this:
int chunkSize = 3;
string a = "0123456789";
int len = a.Length;
StringBuilder sb = new StringBuilder(len + len / chunkSize);
int firstIdx = len % chunkSize;
sb.Append(a.Substring(0, firstIdx));
sb.Append(" ");
for (int i = firstIdx; i < len; i += chunkSize)
{
sb.Append(a.Substring(i, chunkSize));
sb.Append(" ");
}
a = sb.ToString();
Related
public PriceChangeRequestStatus SelectPcrFrom(String[] fromdate)
{
wrapper.Click(imgPcrFrom);
String year, day, month;
day = fromdate[0];
month = fromdate[1];
year = fromdate[2];
//for (int index = 0; index <= 1; index++)
wrapper.Click(lnkPcrFrom);
wrapper.Click(lnkPcrFrom);
Thread.Sleep(4000);
driver.FindElement(By.XPath("//div[contains(text(),'" + year + "')]")).Click();
Thread.Sleep(4000);
driver.FindElement(By.XPath("//div[contains(text(),'" + findMonth(month).Substring(0, 3) + "')]")).Click();
Thread.Sleep(2000);
driver.FindElement(By.XPath("//div[contains(#title,'" + findMonth(month) + " " + day + ", " + year + "')]")).Click();
Thread.Sleep(2000);
return this;
}
public PriceChangeRequestStatus SelectPcrTo(String[] todate)
{
wrapper.Click(imgPcrTo);
wrapper.Click(lnkPcrTo);
wrapper.Click(lnkPcrTo);
String year, day, month;
day = todate[0];
month = todate[1];
year = todate[2];
Thread.Sleep(4000);
// By Sunayana
//IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
//js.ExecuteScript("document.getElementsByClassName('ajax__calendar_year')");
// End
//// IReadOnlyList<IWebElement> yearClick = wrapper.GetElements("xpath:=.//div[#class='ajax__calendar_year']");
//IList<IWebElement> yearClick = driver.FindElements(By.XPath(".//div[#class='ajax__calendar_year']"));
//Console.WriteLine(yearClick.Count);
//for (int index = 1; index-1 <= yearClick.Count; index++)
//{
// int i=0;
// Console.WriteLine(index);
// i=index;
// if (yearClick[i].GetAttribute("innerHTML").Equals(year))
// {
// yearClick[i].Click();
// Console.WriteLine("I am here");
// }
// else {
// Console.WriteLine("Sorry");
// }
//}
Thread.Sleep(4000);
//var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
//try
//{
// wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[contains(text(),'" + year + "')]"))).Click();
//}
//catch (WebDriverTimeoutException)
//{
// Console.WriteLine("Logout button was not visible!");
//}
IWebElement clickyear = driver.FindElement(By.XPath("//div[contains(text(),'" +year+ "')]"));
clickyear.Click();
//Actions action = new Actions(driver);
//action.MoveToElement(clickyear).Click().Build().Perform();
Thread.Sleep(4000);
driver.FindElement(By.XPath("//div[contains(text(),'" + findMonth(month).Substring(0, 3) + "')]")).Click();
Thread.Sleep(2000);
driver.FindElement(By.XPath("//div[contains(#title,'" + findMonth(month) + " " + day + ", " + year + "')]")).Click();
Thread.Sleep(2000);
return this;
}
public String findMonth(String month)
{
String CorrectMonth = "";
switch (month) {
case "01":
CorrectMonth = "January";
break;
case "02":
CorrectMonth = "February";
break;
case "03":
CorrectMonth = "March";
break;
case "04":
CorrectMonth = "April";
break;
case "05":
CorrectMonth = "May";
break;
case "06":
CorrectMonth = "June";
break;
case "07":
CorrectMonth = "July";
break;
case "08":
CorrectMonth = "August";
break;
case "09":
CorrectMonth = "September";
break;
case "10":
CorrectMonth = "October";
break;
case "11":
CorrectMonth = "November";
break;
case "12":
CorrectMonth = "December";
break;
}
return CorrectMonth;
}
Edited the code and tried running the script. The logic written for SELECTPCRFROM is working fine but the same logic is not working for SELECTPCRTO. tried many others solutions but still SELECTPCRTO is nor working as expected Please help me on this. The executed code is displaying error message provided in the title
Most of the datepickers gets identified by xpath but when you try perform an operation on them then they would give you an error. Instead try going the javascript way.
Java -
document.evaluate(PATH, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
Similary you can use it in C#
Refer the answer here - link
I can collect longitude and latitude info from GNGGA data get from GPS/GNSS board, but I can't draw a path according to longitude and latitude information.
For example you can see in picture;
In pıcture there is a also direction.For the first step direction is not important. I just want to draw it wiht points or lines without direction(if it is possible).To be trust, I tried to draw in chart and picture box but I couldn't achieve it.
Have you got any ideas about it?
Here is my code; gBoylam=longitude, gEnlem=lattitude, gYukseklik=altitude
gParca=NMEA.Split(new char[] { ',' });
switch (gParca[0])
{
//Global Positioning System Fix data
case "$GNGGA":
gParca[2] = gParca[2].Replace('.', ',');
gParca[4] = gParca[4].Replace('.', ',');
if (gParca[3]=="N")
{
gKG = "North";
}
else if(gParca[3]=="S")
{
gKG = "South";
}
if (gParca[5]=="E")
{
gDB = "East";
}
else if(gParca[5]=="W")
{
gDB = "West";
}
switch (gParca[6])
{
case "0": gKilitlenme = "Invalid"; break;
case "1": gKilitlenme = "GPS fix (SPS)"; break;
case "2": gKilitlenme = "DGPS fix"; break;
case "3": gKilitlenme = "PPS fix"; break;
case "4": gKilitlenme = "RTK fix"; break;
case "5": gKilitlenme = "RTK float"; break;
case "6": gKilitlenme = "Estimated"; break;
case "7": gKilitlenme = "Manuel Input"; break;
case "8": gKilitlenme = "Simulation"; break;
default: gKilitlenme = "Unknown"; break;
}
gEnlem = gParca[2];
gBoylam = gParca[4];
gUydular = gParca[7];
gYukseklik = gParca[9] + " " + gParca[10];
// gVeriTipi = "GPS Data Fix";
gSaat = gParca[1].Substring(0, 2) + ":" + gParca[1].Substring(2, 2) + " " +
gParca[1].Substring(4, 2) + " (UTF)";
gYataySapma = gParca[8];
GPSData(NMEA);
break;
default:
break;
}
txtbxLongitude.Text = gBoylam + " " + gDB;
txtbxLatitude.Text = gEnlem + " " + gKG;
txtbxAltitude.Text = gYukseklik;
txtbxFixQuality.Text = gKilitlenme;
txtbxSatellites.Text = gUydular;
txtbxTime.Text = gSaat;
whatever the input is it should print the answer in words(no limits) For example input is 2 it should answer in words "TWO" few more examples to understand 12 = "twelve" ,51 = "fifty one", 1000 = "One thousand",2005 = "two thousand and five" and so on...
Check out great Humanizer project. It has exactly what you need.
3501.ToWords() => "three thousand five hundred and one"
Try this approach:
It's not a complete code, you can improve it by recursive call with
proper range checking etc.
Create a function with input parameter range from 0 to 99 (as shown below):
private string DigitToTextConverter(int digit)
{
string digitText = "";
switch (digit)
{
case 0:
digitText = "zero";
break;
case 1:
digitText = "one ";
break;
case 2:
digitText = "two ";
break;
case 3:
digitText = "three ";
break;
case 4:
digitText = "four ";
break;
case 5:
digitText = "five ";
break;
case 6:
digitText = "six ";
break;
case 7:
digitText = "seven ";
break;
case 8:
digitText = "eight ";
break;
case 9:
.....;
case 10:
.....
case 99:
.....
default:
break;
}
return digitText;
}
//Call this function with appropriate parameter: (suppose user entered 1234)
var userInput = 1234;
var digitText = new StringBuilder();
var quotient = userInput / 1000;
string convertedText = DigitToTextConverter(quotient);
digitText.Append(convertedText + " thousand");
digitText.AppendFormat(" ");
var remainder = userInput % 1000;
quotient = remainder / 100;
convertedText = DigitToTextConverter(quotient);
digitText.Append(convertedText + " thundred");
digitText.AppendFormat(" ");
remainder = remainder % 100;
//Complete remaining portion, better to have a function with recursive call
string finalText = digitText.ToString();
I have been trying to generate passwords sequentially in C# (aaaa, aaab, aaac, ... abcd, abce) for a hash cracker (for white-hat purposes). However, I'm not sure how to do that.
Right now I have a char array, the last element of which is being incremented by a switch:
switch (character) {
case ('0'):
character = '1';
break;
case ('1'):
character = '2';
break;
case ('2'):
character = '3';
break;
case ('3'):
character = '4';
break;
case ('4'):
character = '5';
break;
case ('5'):
character = '6';
break;
case ('6'):
character = '7';
break;
case ('7'):
character = '8';
break;
case ('8'):
character = '9';
break;
case ('9'):
character = 'a';
break;
case ('a'):
character = 'b';
break;
case ('b'):
character = 'c';
break;
case ('c'):
character = 'd';
break;
case ('d'):
character = 'e';
break;
case ('e'):
character = 'f';
break;
case ('f'):
character = 'g';
break;
case ('g'):
character = 'h';
break;
case ('h'):
character = 'i';
break;
case ('i'):
character = 'j';
break;
case ('j'):
character = 'k';
break;
case ('k'):
character = 'l';
break;
case ('l'):
character = 'm';
break;
case ('m'):
character = 'n';
break;
case ('n'):
character = 'o';
break;
case ('o'):
character = 'p';
break;
case ('p'):
character = 'q';
break;
case ('q'):
character = 'r';
break;
case ('r'):
character = 's';
break;
case ('s'):
character = 't';
break;
case ('t'):
character = 'u';
break;
case ('u'):
character = 'v';
break;
case ('v'):
character = 'w';
break;
case ('w'):
character = 'x';
break;
case ('x'):
character = 'y';
break;
case ('y'):
character = 'z';
break;
case ('z'):
character = 'A';
break;
case ('A'):
character = 'B';
break;
case ('B'):
character = 'C';
break;
case ('C'):
character = 'D';
break;
case ('D'):
character = 'E';
break;
case ('E'):
character = 'F';
break;
case ('F'):
character = 'G';
break;
case ('G'):
character = 'H';
break;
case ('H'):
character = 'I';
break;
case ('I'):
character = 'J';
break;
case ('J'):
character = 'K';
break;
case ('K'):
character = 'L';
break;
case ('L'):
character = 'M';
break;
case ('M'):
character = 'N';
break;
case ('N'):
character = 'O';
break;
case ('O'):
character = 'P';
break;
case ('P'):
character = 'Q';
break;
case ('Q'):
character = 'R';
break;
case ('R'):
character = 'S';
break;
case ('S'):
character = 'T';
break;
case ('T'):
character = 'U';
break;
case ('U'):
character = 'V';
break;
case ('V'):
character = 'W';
break;
case ('W'):
character = 'X';
break;
case ('X'):
character = 'Y';
break;
case ('Y'):
character = 'Z';
break;
case ('Z'):
character = '#';
break;
case ('#'):
character = '%';
break;
case ('%'):
character = '/';
break;
case ('/'):
character = '\\';
break;
case ('\\'):
character = '\'';
break;
case ('\''):
character = '!';
break;
case ('!'):
character = '$';
break;
case ('$'):
character = '#';
break;
case ('#'):
character = '^';
break;
case ('^'):
character = '?';
break;
case ('?'):
character = ':';
break;
case (':'):
character = ',';
break;
case (','):
character = '(';
break;
case ('('):
character = ')';
break;
case (')'):
character = '[';
break;
case ('['):
character = ']';
break;
case (']'):
character = '{';
break;
case ('{'):
character = '}';
break;
case ('}'):
character = '-';
break;
case ('-'):
character = '_';
break;
case ('_'):
character = '+';
break;
case ('+'):
character = '=';
break;
case ('='):
character = '0';
break;
prev = true;
default:
character = '0';
break;
}
However, when that element reaches 0 again, I need to increment the previous digit of the password and if that digit also reaches 0, I need to increment the previous digit from that one, and so on.
Also, since this is a hash cracker, it needs to be fast. Any suggestions?
My first answer wouldn't give you quite what you want. This will:
Create a string that defines your alphabet:
const string Alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
Then initialize an int array with all -1, as long as your longest password. This one will do up to 8 characters:
int[] pwArray = new int[] {-1, -1, -1, -1, -1, -1, -1, -1};
Then run a loop:
for (int i = 0; i < Whatever; ++i)
{
string password = ToPasswordString(pwArray, Alphabet);
// do something with the password
}
string ToPasswordString(int[] pass, string alphabet)
{
for (int i = pass.Length-1; i > 0; --i)
{
pass[i]++;
if (pass[i] < alphabet.Length)
{
break;
}
pass[i] = 0;
}
var sb = new StringBuilder();
for (int i = 0; i < pass.Length; ++i)
{
if (pass[i] >= 0)
sb.Append(alphabet[pass[i]]);
}
return sb.ToString();
}
The key here is that we don't modify password characters. Rather, we modify indexes into the character array.
Granted, this won't be as fast as some other methods (passwords per second), but your program's speed is limited by how fast the site you're hacking can respond to login tries. The amount of time you spend generating passwords is irrelevant when compared to that.
Instead of a complicated and extremely large switch statement why not just directly map int values to char.
for (int i = 0; i < (int)Char.MaxValue; i++) {
char c = (char)i;
...
}
This would allow you to build up brute force password generator pretty easily.
You could use ascii code, for sample:
public char GetNextChar(char c)
{
return (char)(((int)c) + 1);
}
Would be a nice extension, for sample:
public static class Extensions
{
public static char GetNextChar(this char c)
{
return (char)(((int)c) + 1);
}
}
and using it:
character = character.GetNextChar();
Something like this should work.
char[] currPassword = new char[] { (char)65, (char)65, (char)65, (char)65, (char)65 }; //65 = A
const int Z = 90;
const int A = 65;
void Main()
{
while(true)
{
string curr = new string(currPassword);
Next();
}
}
public void Next()
{
int currIndex = currPassword.Length -1;
bool done = false;
do
{
currPassword[currIndex]++;
if(currPassword[currIndex] > Z && currIndex >= 0)
{
currPassword[currIndex] = (char)A;
currIndex--;
}
else
{
done = true;
}
}while(!done);
}
LINQLIB contains methods to compute all permutations or combinations. You could use it instead although the order might not be exactly as you describe in your question.
Another different approach:
static void Main(string[] args)
{
string charSet = "0123456789!##$%^&*";
string password = "20#";
StringBuilder start = new StringBuilder("0");
int j = 0;
int z = 0;
while (start.ToString() != password)
{
start[z] = charSet[j++];
Console.WriteLine(start);
if (j == charSet.Length)
{
if (start.ToString().Where(c => c == charSet[charSet.Length - 1]).Count() == start.ToString().Length)
{
start.Append("0");
for (int t = 0; t < start.Length; t++)
{
start[t] = '0';
}
z++;
}
else
{
for (int t = start.Length - 2; t >= 0; t--)
{
if (charSet.IndexOf(start[t]) == charSet.Length - 1)
{
start[t] = '0';
}
else
{
start[t] = charSet[charSet.IndexOf(start[t]) + 1];
break;
}
}
}
j = 0;
}
}
}
Just treat each of your password entries as numbers, its base being the number of characters present in the initial Dictionary. Whenever you reach a maximum in a given position, you 'carry over' to the next 'digit'.
This small class will return all possible combinations, given:
an initial character dictionary
a minimum password size
a maximum password size
Just keep in mind that sequences like that get EXTREMELY large very fast, depending on the initial dictionary size. For example, the following code with default values (minChar=2,MaxChar=4) generates 866495 entries.
public class Sequencer
{
public string characterDictionary = "0123456789";
//public string characterDictionary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=[];',./`~!##$%^&*()_+{}|:\"<>?|\\";
public int minCharCount = 2;
public int maxCharCount = 4;
private List<string> _sequence;
public List<string> GetSequence()
{
_sequence = new List<string>();
for (int i = minCharCount; i < (maxCharCount + 1); i++)
RenderCombinations(i);
return _sequence;
}
private void RenderCombinations(int charCount)
{
int _dictSize = characterDictionary.Length;
int[] _containerMatrix = new int[charCount];
char[] _splitDict = characterDictionary.ToCharArray();
bool _maxReached = false;
do
{
string _currentCombination = "";
for (int i = 0; i < charCount; i++)
_currentCombination += _splitDict[_containerMatrix[i]];
_sequence.Add(_currentCombination);
// Let the shifting begin!
bool _mustCarry = false;
int _carryIndex = 0;
do
{
_mustCarry = false;
if (_carryIndex == _containerMatrix.Length)
{
_maxReached = true;
break;
}
_containerMatrix[_carryIndex]++;
if (_containerMatrix[_carryIndex] == _dictSize)
{
_mustCarry = true;
_containerMatrix[_carryIndex] = 0;
}
_carryIndex++;
if (_carryIndex > charCount)
{
_mustCarry = false;
_maxReached = true;
}
} while (_mustCarry);
} while (!_maxReached);
}
}
I have absolutely no idea what to do with this but here is a snippet of the file that I'm trying to convert:
"September
3Beef
Lamb Chops
4Fish
Not Fish
5Mac and Cheese
PB & J"
The csv file is supposed to print the date what comes after in quotes, so the above should look like:
Tuesday September Third 2013 "Beef" "Lamb Chops"
Wednesday September Fourth 2013 "Fish" "Not Fish"
Thursday September Fifth 2013 "Mac and Cheese" "PB&J"
Here is what I have so far:
StreamReader reader = new StreamReader(#"..\..\Lunches.txt");
while (!reader.EndOfStream)
{
string currentLine = reader.ReadLine();
}
StreamWriter writer = new StreamWriter(#"..\..\Lunches.csv");
// date.ToString("ddddd yyyyy mm MMMMMM");
string delimiter = ",";
Here is the code
private void Form1_Load(object sender, EventArgs e)
{
string sayka = "August\n\n" +
"31Beef\n" +
"Lamb Chops\n" +
"24Fish\n" +
"Not Fish\n" +
"15Mac and Cheese\n" +
"PB & J\n";
MessageBox.Show(makeCSV(sayka));
}
string getMonthName(int val)
{
switch (val)
{
case 1: return "JANUARY";
case 2: return "FEBRUARY";
case 3: return "MARCH";
case 4: return "APRIL";
case 5: return "MAY";
case 6: return "JUNE";
case 7: return "JULY";
case 8: return "AUGUST";
case 9: return "SEPTEMBER";
case 10: return "OCTOBER";
case 11: return "NOVEMBER";
case 12: return "DECEMBER";
default: return null;
}
}
string getDayName(int val)
{
switch (val)
{
case 1: return "First";
case 2: return "Second";
case 3: return "Third";
case 4: return "Fourth";
case 5: return "Fifth";
case 6: return "Sixth";
case 7: return "Seventh";
case 8: return "Eighth";
case 9: return "Nineth";
case 10: return "Tenth";
case 11: return "Eleventh";
case 12: return "Twelth";
case 13: return "Thirteenth";
case 14: return "Fouteenth";
case 15: return "Fifteenth";
case 16: return "Sixteenth";
case 17: return "Seventeenth";
case 18: return "Eighteenth";
case 19: return "Nineteenth";
case 20: return "Twentieth";
default: return "";
}
}
string getDayName2(int val)
{
if (val == 30) return "Thirtieth";
else if (val > 30) return "Thirty " + getDayName(val % 30);
else if (val > 20) return "Twenty " + getDayName(val % 20);
else return getDayName(val);
}
string makeCSV(string val)
{
string res = "";
string[] ss = val.Split('\n');
int curMonth = 0;
for (int i = 0; i < ss.Length; i++)
{
if (ss[i].Trim() != "")
{
bool isInt = false;
try
{
int intA = Convert.ToInt32(ss[i][0].ToString());
isInt = true;
}
catch { }
if (isInt)
{
bool isDoubleInt = false;
try
{
int intB = Convert.ToInt32(ss[i][1].ToString());
isDoubleInt = true;
}
catch { }
int date = 0;
if (isDoubleInt) date = Convert.ToInt32(ss[i].Remove(2));
else date = Convert.ToInt32(ss[i][0].ToString());
DateTime dt = new DateTime(DateTime.Now.Year, curMonth, date);
string itemName = "";
if (isDoubleInt) itemName = ss[i].Substring(2);
else itemName = ss[i].Substring(1);
string itemName2 = ss[i + 1];
res += dt.DayOfWeek + " " + getMonthName(dt.Month) + " " + getDayName2(dt.Day) + " \"" + itemName + "\"" + " \"" + itemName2 + "\"\n";
}
else
{
for (int j = 1; j < 13; j++)
if (ss[i].ToUpper().StartsWith(getMonthName(j)))
{
curMonth = j;
break;
}
}
}
}
return res;
}
}
From the filestream either use StreamReader.readToEnd(), get the string and use the function, Or if the file is big then use it line by line..
Rate if this helps..
This is going to be a bit complicated. I left out some things for you to do.
String[] months = { "January", "February", "March", ....};
Date processDate = new Date();
while (!reader.EndOfStream)
{
string currentLine = reader.ReadLine();
// skip this line if blank
if (String.IsNullOrEmpty(currentLine)) continue;
if (months.Contains(currentLine)) {
// we have a new starting month.
// reset the process date
Int32 month = DateTime.ParseExact(currentLine.Trim(), "MMMM", CultureInfo.CurrentCulture).Month;
date = Convert.ToDate(month.ToString() + "/01/2013");
continue;
}
// here's where the real fun begins:
// you have to pull out the first two characters and test if one or both are digits.
// This will give you the day. Put that into your date variable.
Int32 day = 0;
char[] arr = currentLine.ToCharArray(0, currentLine.Length);
if (Char.IsDigit(arr[1])) {
// first two characters are numbers
day = Convert.ToInt32(currentLine.Substring(0,2));
currentLine = currentLine.Remove(0,2);
} else {
// only the first character is a number
day = Convert.ToInt32(currentLine.Substring(0,1));
currentLine = currentLine.Remove(0,1);
}
// set the new date
date = new DateTime(date.Year, date.Month, day, 0, 0, 0);
// If we can assume that ALL lines are broken into two parts then we can do the following:
String secondLine = reader.ReadLine();
currentLine = String.Format("{0} {1}", currentLine, secondLine);
// At this point you have the month, day, and the entire line.
// write it to your lunch stream or store in a StringBuilder
}