- 1
- 2
- 3
- 4
- 5
- 6
- 7
static bool EqStr(string s)
{
Regex r = new Regex(@"STRING");
Match m = r.Match(s);
if (m.Success == true) return true;
else return false;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+95.7
static bool EqStr(string s)
{
Regex r = new Regex(@"STRING");
Match m = r.Match(s);
if (m.Success == true) return true;
else return false;
}
Изощренный способ сравнивать строки :)
+136
public string generateEMail()
{
string res;
int i = PersonName.IndexOf(" ");
char[] str1 = new char[i];
PersonName.CopyTo(0, str1, 0, i);
string str11 = new string(str1);
char[] str2 = new char[PersonName.Length - i - 1];
PersonName.CopyTo(i + 1, str2, 0, PersonName.Length - i - 1);
string str22 = new string(str2);
res = str11.ToString() + "." + str22.ToString();
if (res.Length > 20)
{
str1 = new char[20];
res.CopyTo(0, str1, 0, 20);
res = new string(str1);
}
res += "@domain.ua";
return res;
}
Вот вам шаблон для получения емейла из имени и фамилии сотрудника.
+123.7
Request.QueryString["outer_email"] = null;
Это я намерил на несколько места :)
+126.4
foreach (object item in this.cbFind.Properties.Items)
{
int a = -1;
}
+129
public Int32 SectionType
{
get
{
if (this.StaticRecord) return -1;
if ((!this.SectionIsReference) && this.SectionDoNotMakeUp) return 4;
if (this.SectionIsSlave)
{
switch (this.SectionUnionMode)
{
case 1:
return 2;
case 2:
return 0;
default:
return 1;
}
}
if (this.SectionIsReference) return 5;
if (this.SectionIsUnion) return 3;
return 0;
}
}
Собственноручно нагадил...
+136.7
void parseDate(String str, ref int day, ref int month, ref int year)
{
String[] strings = str.Split('/');
day = Int32.Parse(strings[0]);
month = Int32.Parse(strings[1]);
year = Int32.Parse(strings[2]);
}
bool validateDate(String s)
{
//let the data be null
if (s == null || s == "")
return true;
try
{
String[] strings = s.Split('/');
if (strings.Length != 3)
return false;
String day = strings[0];
if (Int32.Parse(day) > 31)
{
return false;
}
String month = strings[1];
if (Int32.Parse(month) > 12)
{
return false;
}
String year = strings[2];
if (year.Length != 4)
{
return false;
}
}
catch (SystemException)
{
return false;
}
return true;
}
int compareDates(String s1, String s2)
{
if (s1 == "" && s2 != "")
return -1;
if (s1 == s2)
return 0;
if (s1 != "" && s2 == "")
return 1;
int day1 = 0, month1 = 0, year1 = 0, day2 = 0, month2 = 0, year2 = 0;
parseDate(s1, ref day1, ref month1, ref year1);
parseDate(s2, ref day2, ref month2, ref year2);
if (year1 > year2)
return -1;
if (year1 < year2)
return 1;
if (month1 > month2)
return -1;
if (month2 < month1)
return 1;
if (day1 > day2)
return -1;
if (day2 > day1)
return 1;
return 0;
}
no comments
+947.7
foreach (string id in sourceIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
sourceId = Convert.ToInt32(id);
break;
}
Как взять первую цифру в строке - конечно без цикла тут никак
+98
static void CompressFile(string inFilename,
string outFilename)
{
FileStream sourceFile = File.OpenRead(inFilename);
FileStream destFile = File.Create(outFilename);
// Create the Compressed stream
GZipStream compStream =
new GZipStream(destFile, CompressionMode.Compress);
// Write the data
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
// Clean it up
sourceFile.Close();
compStream.Close();
destFile.Close();
}
Пример из книги "Microsoft .NET Framework 2.0 Application Development Foundation", официального пособия для подготовки к экзамену 70-536.
Угадайте, почему "сжатые" файлы получаются больше несжатых.
+135.9
StiReport report = // создание отчета StimulSoft Reporter
// . . . . .
// . . . . .
string tempfilename = System.Guid.NewGuid().ToString() + ".tmp";
report.ExportDocument(StiExportFormat.Word2007, tempfilename); //позволяет конвертировать отчет только в поток
FileStream stream = new FileStream(tempfilename, FileMode.Open);
byte[] reportFile = new byte[stream.Length];
stream.Read(reportFile, 0, (int)stream.Length);
stream.Close();
File.Delete(tempfilename);
if (reportFile.Length > 0)
if (MessageBox.Show("Зберегти друковану форму?", "Запит", MessageBoxButtons.OKCancel) == DialogResult.OK)
WriteToDB(reportFile, "Документ.docx");
+105.3
public class ImportService : System.Web.Services.WebService
{
private const string KEY = "*******";
[WebMethod]
public void AddFileInQueue(string aKey, ..., out String error)
{
...
if (KEY == aKey)
...
else
{
error = "Invalid key";
}
}
}
Мне предложили использовать эту же авторизацию для нового веб-сервиса в том же проекте со словами "there is normal login implemented somewhere"