1. C# / Говнокод #3924

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    public static List<string> GetWords(string text, out List<int> index)
            {
                MatchCollection matches = Regex.Matches(text, @"[\w.]+|[\W]+");
                List<string> m = new List<string>();
                index = new List<int>();
                foreach (Match match in matches)
                {
                    if (match.Value.IndexOf('.', match.Value.Length - 1) != -1 && !isPart(match.Value) && match.Value.Length > 1)
                    {
                        string str = match.Value.Remove(match.Value.Length - 1, 1);
                        m.Add(str);
                        m.Add(".");
                    }
                    else
                    {
                        m.Add(match.Value);
                        index.Add(match.Index);
                    }
                }
                return m;
            }

    Нужно подать текст, который будет разбит на <Word> ... </Word>. При этом нужно отслеживать сокращения типа "г.", "т.д.", "др" и т.д. Но возникает проблема, слова типа "привет." будут также рассматриваться как единое целое, поэтому приходиться проверять, сокращение это или нет в строках 8-13, если есть другой (оптимальный) способ, то был бы благодарен )

    Attila, 10 Августа 2010

    Комментарии (10)
  2. C# / Говнокод #3915

    +114

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    static void Main(string[] args)
            {
    
            metka:
                int exit = 0;
                Console.Clear();
                TextRead ob1 = new TextRead();
                Meneger ob2 = new Meneger();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("                             " + "ДОБРО ПОЖАЛОВАТЬ");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("--------------------------------------------------------------------------------");
                Thread.Sleep(500);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Выберите нужную программу:");
                Thread.Sleep(500);
                Console.WriteLine();
                string vib;
                Console.WriteLine("1)Текстовый редактор");
                Thread.Sleep(500);
                Console.WriteLine("2)Файловый менеджер");
                Console.WriteLine("3)Выход");
                vib = Console.ReadLine();
                switch (vib)
                {
                    case "1" : ob1.read();
                        break;
                    case "2": ob2.med();
                        break;
                    case "3":  exit = 1;
                        break;
                    default: Console.WriteLine("Выберите 1 или 2 ");
                        break;
                }
               
                
                if (exit == 0)
                {
                    goto metka;
                }
    
               
                
            }

    Имитация загрузки
    Thread.Sleep(500);хВВDDDD

    Nigma143, 08 Августа 2010

    Комментарии (10)
  3. C# / Говнокод #3914

    +115

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    public void F2()
            {
                Console.Clear();
                try
                {
                    Console.Write("Введите имя файла для добавления данных:");
                    string str1 = Console.ReadLine();
                    try
                    {
                        FileStream dd = new FileStream("C:\\" + str1 + ".txt", FileMode.Open);
                        dd.Close();
                    }
                    catch
                    {
                        Console.WriteLine(" Файл с таким именем не существует ");
                        Console.WriteLine(" Будет создан новый файл");
                        Console.WriteLine();
                        Console.WriteLine(" Нажмите Enter для продолжения");
                        Console.ReadLine();
                        
                    }
                    
                    Console.Clear();
                    FileStream f = new FileStream("C:\\" + str1 + ".txt", FileMode.Append);
                    StreamWriter zapis = new StreamWriter(f);
                    Console.WriteLine("вводите текст , 'стоп' для завершения");
                    string s;
                    do
                    {
                        Console.Write(": ");
                        s = Console.ReadLine();
                        if (s != "стоп")
                        {
                            s = s + "\r\n";
                            zapis.Write(s);
                        }
                    }
                    while (s != "стоп");
                    zapis.Close();
                    f.Close();
                    Console.WriteLine("Файл успешно добавлен");
                    
                }
                   
                catch
                {
                    Console.WriteLine("error");
                }
            }

    Проверка на существования файла

    Nigma143, 08 Августа 2010

    Комментарии (9)
  4. C# / Говнокод #3913

    +114

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    Console.Clear();
                try
                {
                    Console.Write("Введите имя нового файла:");
                    string str1 = Console.ReadLine();
                    FileStream f = new FileStream("C:\\" + str1 + ".txt", FileMode.Create);
                    StreamWriter zapis = new StreamWriter(f);
                    Console.WriteLine("вводите текст , 'стоп' для завершения");
                    string s;
                    do
                    {
                        Console.Write(": ");
                        s = Console.ReadLine();
                        if (s != "стоп")
                        {
                            s = s + "\r\n";
                            zapis.Write(s);
                        }
                    }
                    while (s != "стоп");
                    zapis.Close();
                    f.Close();
                    Console.WriteLine("Файл успешно запишен");
    
                }
                catch
                {
                    Console.WriteLine("error");
                }

    Школота атакЭ
    "запишен"хD

    Nigma143, 08 Августа 2010

    Комментарии (2)
  5. C# / Говнокод #3894

    +124

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    public void GeneratXMLForChatServerControl()
            {
                List<ClassUsersList> List = GetUsersList();
                System.IO.StreamWriter TextW = new System.IO.StreamWriter("Update_Settings.xml", false,System.Text.Encoding.GetEncoding("UTF-8"));
                
                TextW.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                TextW.WriteLine("<General>");
                foreach (ClassUsersList User in List)
                {
                    User.Information = User.Information.Replace("<", "");
                    User.Information = User.Information.Replace(">", "");
                    User.Information = User.Information.Replace("&", "");
                    TextW.WriteLine("<Name>" + User.Information + "</Name>");
                    TextW.WriteLine("<Login>" + User.UIN + "</Login>");
                    TextW.WriteLine("<Password>" + User.Pwd + "</Password>");
                    TextW.WriteLine("<LocalPath>D:\\chat2\\" + User.UID + "\\</LocalPath>");
                    TextW.WriteLine("<UID>" + User.UID + "</UID>");
                    TextW.WriteLine("<UIN>" + User.UIN + "</UIN>");
                    TextW.WriteLine("<Lock>0</Lock>");
                    TextW.WriteLine("");
                }
                TextW.WriteLine("</General>");
                TextW.Flush();
                TextW.Close();         
            }

    Крутобл, создаём XML налету

    Nigma143, 06 Августа 2010

    Комментарии (14)
  6. C# / Говнокод #3893

    +111

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    /// <summary>
            /// Получает IPAdress к которому нужно подключиться
            /// </summary>
            private int Get_IPAdress_Server()
            {
                string Buf = "";
                for (int i = 0; i < Server_IP.Servers_IP.Length; i++ )
                {
                    try
                    {
                        TcpClient tc = new TcpClient(Server_IP.Servers_IP[i], Server_IP.Servers_Port[i]);
                        byte[] buffer = new byte[19];
                        NetworkStream nss = tc.GetStream();
                        nss.Read(buffer, 0, 19);
                        Buf = Encoding.ASCII.GetString(buffer).Trim();
                        Server_IPAdress = Buf.Substring(0, Buf.IndexOf(":"));
                        Server_Port = int.Parse(Buf.Substring(Buf.IndexOf(":") + 1, Buf.Length - Buf.IndexOf(":") - 1));
                        return 0;
                    }
                    catch (SocketException)
                    {
                    }
                }
                return -1;
            }

    Получаем индекс в коллекции где хранятся список серверов Первый доступный!

    Nigma143, 06 Августа 2010

    Комментарии (3)
  7. C# / Говнокод #3892

    +112

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    private void _Login()
            {
                if (Get_IPAdress_Server() != 0)
                {
                    if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                    return;
                }
                try
                {
                    TcpClient MClient = new TcpClient(Server_IPAdress, Server_Port);
                    Sock = MClient.Client;
                    if (Sock == null)
                    {
                        if (Error_Connect_Method != null) Error_Connect_Method(this ,"Серевер недоступен!");
                        return;
                    }
                    mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_HELLO, 0, 0, 0, 0, 0, 0, 0);
                    byte[] Hello = Pack.Generat_Packet();
                    Sock.Send(Hello);
                    byte[] Buf = new byte[48];
                    Sock.Receive(Buf);
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_HELLO_ACK)
                    {
                        Sock.Close();
                        if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                    }
                    Ping_Timer = new System.Timers.Timer();
                    long j = 0;
                    Ping_Timer.Interval = mrim_packet_header.Get_UL(Buf.Skip(44).ToArray(), ref j) * 1000;
                    Ping_Timer.Elapsed += new System.Timers.ElapsedEventHandler(Send_Ping);
                    Ping_Timer.Start();
                    Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_LOGIN2, 0, 0, 0, 0, 0, 0, 0);
                    Pack.Add_Date_LPS(new string[] {Login, Password });
                    Pack.Add_Date_UL(new long[] { Status });
                    Pack.Add_Date_LPS(new string[] { User_Agent });
                    byte[] Auth = Pack.Generat_Packet();
                    Sock.Send(Auth);
                    Buf = new byte[48];
                    Sock.Receive(Buf);
                    byte[] Date_Len;
                    byte[] Date;
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_LOGIN_ACK)
                    {
                        Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                        Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                        int N = Sock.Receive(Date);
                        mrim.mrim_packet_header.Loger(Date, N);
                        if (Error_Connect_Method != null) Error_Connect_Method(this, Encoding.GetEncoding("windows-1251").GetString(Date));
                        return;
                    }
                    if (Complite_Connect_Method != null) Complite_Connect_Method(this);
                    Sock.Receive(Buf = new byte[44]);
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) == Msg.MRIM_CS_USER_INFO)
                    {
                        Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                        Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                        int N = Sock.Receive(Date);
                        long M = 0;
                        long J = 0;
                        byte[] Buf_Text;
                        while (N > J)

    Мега авторизация на сервере mrim.mail.ru

    Nigma143, 06 Августа 2010

    Комментарии (2)
  8. C# / Говнокод #3891

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public static byte[] Length_Hex(long _Length)
            {
                byte[] Buf = { (byte)(_Length >> 0), (byte)(_Length >> 8), (byte)(_Length >> 16), (byte)(_Length >> 24) };
                return Buf;
            }

    Кривой велик

    Nigma143, 06 Августа 2010

    Комментарии (19)
  9. C# / Говнокод #3878

    +120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                ComboBox
                    cb = sender as ComboBox;
                TextBox
                    tb = new TextBox();
    
                if (cb == comboBox1)
                {
                    tb = textBox7;
                }
                if (cb == comboBox2)
                {
                    tb = textBox6;
                }
                if (cb == comboBox12)
                {
                    tb = textBox2;
                }
                if (cb == comboBox3)
                {
                    tb = textBox8;
                }
                if (cb == comboBox4)
                {
                    tb = textBox9;
                }
                if (cb == comboBox5)
                {
                    tb = textBox10;
                }
                if (cb == comboBox6)
                {
                    tb = textBox11;
                }
                if (cb == comboBox7)
                {
                    tb = textBox12;
                }
                if (cb == comboBox8)
                {
                    tb = textBox13;
                }
                if (cb == comboBox11)
                {
                    tb = textBox14;
                }
    
                tb.Enabled = !(cb.SelectedIndex > 0);
                tb.Text = (cb.SelectedIndex > 0) ? "" : tb.Text;
            }

    David_M, 05 Августа 2010

    Комментарии (3)
  10. C# / Говнокод #3874

    +116

    1. 1
    2. 2
    var result = resultDate.ToString("yyyy-MM-dd");
    result = result.Replace("-", "");

    zonder, 04 Августа 2010

    Комментарии (8)