вдруг ктот писал прогу на C# с обработкой текста.

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by 9822, 13 May 2009.

Thread Status:
Not open for further replies.
  1. 9822

    9822 Banned

    Joined:
    3 Aug 2005
    Messages:
    273
    Likes Received:
    29
    Reputations:
    8
    тему можно закрыть спасиб :)
     
    #1 9822, 13 May 2009
    Last edited: 13 May 2009
  2. login999

    login999 Elder - Старейшина

    Joined:
    12 Jun 2008
    Messages:
    491
    Likes Received:
    280
    Reputations:
    92
    пример на Python:

    Code:
    #!/usr/bin/python
    # -*- coding: cp1251 -*-
    
    with open("source.txt") as inpt:
        with open("out.txt", "a") as out:
            for line in inpt:
                line = line.replace("\r", "").replace("\n", "")
                check_line = line.replace(" ", "")
                if check_line.isdigit():
                    pass
                else:
                    line = line.split(" ")
                    for word in line:
                        word = word.strip()
                        if not word.isdigit():
                            out.write(word+" ")
                    out.write("\n")
    #(c) :D
    
    source.txt:
    Code:
    1 download 1 750 000 000 27 266
    2 mcafee download free trial 1 960 000 15 631
    14 295
    4 download music 298 000 000 11 141
    5 bootleg movie download 1 360 000 8 941
    6 golden casino download http 2 290 000 8 842
    7 latest dota 6.45ai map download 2 470 7 493
    
    на выходе в out.txt:
    Code:
    download 
    mcafee download free trial 
    download music 
    bootleg movie download 
    golden casino download http 
    latest dota 6.45ai map download 
    
     
    1 person likes this.
  3. W!z@rD

    W!z@rD Борец за русский язык

    Joined:
    12 Feb 2006
    Messages:
    973
    Likes Received:
    290
    Reputations:
    43
    regex


    PHP:
    using System;
    using System.Text.RegularExpressions;

    namespace 
    ConsoleApplication1
    {
        class 
    Program
        
    {
            private static 
    string str "1 download 1 750 000 000 27 266" +
                                 
    "2 mcafee download free trial 1 960 000 15 631 14 295" +
                                 
    "4 download music 298 000 000 11 141" +
                                 
    "5 bootleg movie download 1 360 000 8 941" +
                                 
    "6 golden casino download http 2 290 000 8 842" +
                                 
    "7 latest dota 6.45ai map download 2 470 7 493";

            static 
    void Main()
            {
                var 
    = new Regex(@"[^0-9]");
                foreach (
    Match m in r.Matches(str))
                {
                    
    Console.WriteLine(m.Value);
                }
                
    Console.ReadLine();
            }
        }
    }
    вся задача сводится к использованию регулярных выражений

    p.s. подфикси свою грамматику русского языка...
     
    #3 W!z@rD, 13 May 2009
    Last edited: 13 May 2009
  4. 9822

    9822 Banned

    Joined:
    3 Aug 2005
    Messages:
    273
    Likes Received:
    29
    Reputations:
    8
    W!z@rD - спасиб =)
    давай русский язык трогать не будем =)
     
Thread Status:
Not open for further replies.