+129
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
public void ReadFromFile()
{
LoadIntervals = new TimeIntervals(Color.Black);
StreamReader tReader = null;
tReader = File.OpenText("DefaultIntervals");
string income = null;
while ((income = tReader.ReadLine()) != null)
{
// string income = tReader.ReadLine();
string colorR = null; string colorG = null; string colorB = null; string colorA = null; string interval = null;
int i = 0;
for (i = 4; i < income.Length; i++)
{
if (income[i] != ',')
{
interval += income[i];
}
else { break; }
}
for (int a = i + 10; a < income.Length; a++)
{
if (income[a] != ',')
{
colorA += income[a];
}
else
{
for (int r = a + 4; r < income.Length; r++)
{
if (income[r] != ',')
{
colorR += income[r];
}
else
{
for (int g = r + 4; g < income.Length; g++)
if (income[g] != ',')
{
colorG += income[g];
}
else
{
for (int b = g + 4; b < income.Length; b++)
if (income[b] != ',')
{
if (income[b] != ']')
colorB += income[b];
}
else
{
break;
}
break;
}
break;
}
}
break;
}
}
TimePoint tp = new TimePoint(Convert.ToDouble(interval), Color.FromArgb(Convert.ToInt32(colorA), Color.FromArgb(Convert.ToInt32(colorR), Convert.ToInt32(colorG), Convert.ToInt32(colorB))));
LoadIntervals.Add(tp);
}
tReader.Close();
Intervals = LoadIntervals;
}
Так мы парсим файл конфигов вида. (Формат придуман автором кода)
Int=3,Color [A=223, R=253, G=4, B=38]
Int=10,Color [A=255, R=86, G=86, B=185]
Int=20,Color [A=200, R=255, G=215, B=0]
Int=50,Color [A=200, R=255, G=165, B=0]
lomomike,
15 Июня 2011
+128
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
if (body.ToLower().Contains("pr") ||
subject.Contains("PM") ||
subject.Contains("pm") ||
subject.Contains("Pm") ||
subject.Contains("pM") ||
subject.Contains("PMR") ||
subject.Contains("prs") ||
subject.ToLower().Contains("prt") ||
subject.ToLower().Contains("prm") ||
subject.ToLower().Contains("pmt") ||
subject.ToLower().Contains("pmk") ||
subject.ToLower().Contains("pml") ||
subject.ToLower().Contains("pal"))
{
result = true;
}
Пишут друзья из Норвегии
jenik15,
15 Июня 2011
+126
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
public static bool ValidateEmailAddress(string emailAddress)
{
try
{
string TextToValidate = emailAddress;
// test email address with expression
if (emailExpression.IsMatch(TextToValidate))
{
// is valid email address
return true;
}
else
{
// is not valid email address
return false;
}
}
catch (Exception)
{
throw;
}
}
public static bool ValidateEmailAddress(string emailAddress)
{
if(string.IsNullOrEmpty(emailAddress))
return false;
return emailExpression.IsMatch(TextToValidate);
}
jenik15,
14 Июня 2011
+127
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
private string CalculateDecadeOrYear(string year)
{
string decade = year.Remove(3) + "0";
string currentYear = DateTime.Now.Year.ToString();
string currentDecade = currentYear.Remove(3) + "0";
string prevDecade = ((Convert.ToInt32(currentYear.Remove(3)) - 1)).ToString() + "0";
if (!(decade == currentDecade) && !(decade == prevDecade))
{
return decade;
}
return year;
}
stringly typed вычисление декады. нашел в исходниках индусов
overberk,
14 Июня 2011
+121
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
// первай варянт
string[] GetMonth =
{
"Январь", "Февраль", "Март", "Апрель",
"Май", "Июнь", "Июль", "Август", "Сентябрь",
"Октябрь", "Ноябрь", "Декабрь"
};
for (int i = 1; i <= 12; i++)
{
Console.WriteLine(GetMonth[i]);
}
// вторый варянт
System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
for(int i = 1; i <= 12; i++)
{
string strMonthName = mfi.GetMonthName(i).ToString();
Console.WriteLine(strMonthName);
}
Как в C# автоматически получить массив или список всех месяцев года (январь ... декабрь)?
Paragraf,
12 Июня 2011
+126
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
FileStream fsSource = new FileStream(fileName, FileMode.Open, FileAccess.Read);
byte[] b = new byte[8192];
int[] a = new int[4096];
fsSource.Read(b, 0, 8192);
int sum=0;
int elem;
for (int i = 0; i < 4096; i++)
{
elem = b[i * 2] * 256 + b[i*2+1];
a[i] = elem; //раз уж нам всё равно надо заполнять этот массив, то мы его заполним
sum += elem;
}
задача: считать 2-х байтные числа с бинарного файла и посчитать его сумму.
slirx,
12 Июня 2011
+125
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
using System.Diagnostics;
//
private static void ResetAdminPass(string NewPass)
{
//Create New Process
Process QProc = new Process();
// Do Something To hide Command(cmd) Window
QProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
QProc.StartInfo.CreateNoWindow = true;
// Call Net.exe
QProc.StartInfo.WorkingDirectory = "C:\\windows\\SYSTEM32";
QProc.StartInfo.FileName = "net.exe";
QProc.StartInfo.UseShellExecute = false;
QProc.StartInfo.RedirectStandardError = true;
QProc.StartInfo.RedirectStandardInput = true;
QProc.StartInfo.RedirectStandardOutput = true;
// Prepare Command for Exec
QProc.StartInfo.Arguments = @" user administrator " + NewPass;
QProc.Start();
// MyProc.WaitForExit();
QProc.Close();
}
//
http://www.codeproject.com/KB/threads/Reset-Administrator-Pass.aspx
индусы просто охуительны
bugmenot,
11 Июня 2011
+126
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
private string ReadFile(string filePath)
{
string fileText = string.Empty;
int openAttempts = 0;
try
{
using (FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding(1252)))
{
fileText = sr.ReadToEnd();
if (!sr.EndOfStream)
{
sr.Close();
fs.Close();
throw new Exception();
}
}
}
}
catch (Exception ex)
{
//Throw an error if the number of attempts is equal to the number of configured retries
if (openAttempts == 20)
throw new Exception(ex.Message);
else
{
openAttempts += 1;
Thread.Sleep(1000); //Put the thread to sleep for the configured amount of time
ReadFile(filePath);
}
}
return fileText;
}
Тут все, и управление исключениями, и бессмысленная рекурсия, и глупые ошибки. Про то, что это можно было заменить на одну строчку я молчу даже.
Jabberwok,
10 Июня 2011
+122
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
internal sealed class FontKeeper
{
private static readonly FontConverter s_converter = new FontConverter();
private static readonly Regex s_font = new Regex(@"^(?<name>\w[\s\w]+);\s*(?<size>\d+)pt\s*(?:;(?<style>.*))?$", RegexOptions.IgnoreCase);
private static readonly Regex s_style = new Regex(@"^\s*style\s*=\s*([\w\s,]+)$", RegexOptions.IgnoreCase);
private const int defaultSize = 14;
public FontKeeper(Font font) : this(s_converter.ConvertToString(font)) { }
public FontKeeper(string fontString)
{
Match m = s_font.Match(fontString);
if (!m.Success)
throw new ArgumentException("Неверный формат строки");
Name = m.Groups["name"].Value.Trim();
int sz;
if (!int.TryParse(m.Groups["size"].Value, out sz))
sz = defaultSize;
Size = sz;
//Флаги стиля
ParseStyle(m.Groups["style"].Value);
}
private void ParseStyle(string value)
{
Match m = s_style.Match(value);
if (!m.Success) return;
string[] styles = m.Groups[1].Value.Split(new[] { ',' });
foreach (var style in styles)
{
try
{
Style |= (FontStyle)Enum.Parse(typeof(FontStyle), style.Trim(), true);
}
catch { }
}
}
public string Name { get; set; }
public int Size { get; set; }
public FontStyle Style { get; set; }
public float FontFactor
{
get { return (float)Size / defaultSize; }
set { Size = (int)(value * defaultSize); }
}
public Font CreateFont()
{
return new Font(Name, Size, Style);
}
}
Небольшой класс для хранения и динамического изменения шрифтов
lomomike,
10 Июня 2011
+128
- 1
return Mouse.GetState().LeftButton == ButtonState.Pressed ? _manager.Creatures.Where(el => el.Rectangle.Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 2, 2))).FirstOrDefault() : null;
dotnetdeveloper,
08 Июня 2011