Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Text Fle Filter

Text Fle Filter

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rdop
    wrote on last edited by
    #1

    Hi All How can i filter text file?I have a file Test.txt which have some data like this.

    abc
    abc
    12121
    12121
    12
    12
    133
    133
    133

    Now i want to show data on Button click like this

    abc
    12121
    12
    133

    Plz help me...

    _ _ J L 4 Replies Last reply
    0
    • R rdop

      Hi All How can i filter text file?I have a file Test.txt which have some data like this.

      abc
      abc
      12121
      12121
      12
      12
      133
      133
      133

      Now i want to show data on Button click like this

      abc
      12121
      12
      133

      Plz help me...

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      One alternative is to put the read string into a map. Once you do this, go and read the next string from the file. If this string exists in the map ignore it and do not put it in the map and so on. While displaying, display only the elements present in the map. Hope it helps

      You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

      1 Reply Last reply
      0
      • R rdop

        Hi All How can i filter text file?I have a file Test.txt which have some data like this.

        abc
        abc
        12121
        12121
        12
        12
        133
        133
        133

        Now i want to show data on Button click like this

        abc
        12121
        12
        133

        Plz help me...

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Read line by line into an STL list class and call the unique method. Call the sort method before unique if the data is not already sorted.

        «_Superman_» I love work. It gives me something to do between weekends.

        R N 2 Replies Last reply
        0
        • _ _Superman_

          Read line by line into an STL list class and call the unique method. Call the sort method before unique if the data is not already sorted.

          «_Superman_» I love work. It gives me something to do between weekends.

          R Offline
          R Offline
          rdop
          wrote on last edited by
          #4

          can you give me example.Plz

          1 Reply Last reply
          0
          • _ _Superman_

            Read line by line into an STL list class and call the unique method. Call the sort method before unique if the data is not already sorted.

            «_Superman_» I love work. It gives me something to do between weekends.

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            He needs you do his homework... I guess.

            - ns ami -

            1 Reply Last reply
            0
            • R rdop

              Hi All How can i filter text file?I have a file Test.txt which have some data like this.

              abc
              abc
              12121
              12121
              12
              12
              133
              133
              133

              Now i want to show data on Button click like this

              abc
              12121
              12
              133

              Plz help me...

              J Offline
              J Offline
              Jijo Raj
              wrote on last edited by
              #6

              Hello rdop, You can use std::set to remove duplicate entries. This link will be useful - link[^]. Regards, Jijo.

              _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

              1 Reply Last reply
              0
              • R rdop

                Hi All How can i filter text file?I have a file Test.txt which have some data like this.

                abc
                abc
                12121
                12121
                12
                12
                133
                133
                133

                Now i want to show data on Button click like this

                abc
                12121
                12
                133

                Plz help me...

                L Offline
                L Offline
                Le rner
                wrote on last edited by
                #7

                BOOL flag;
                flag=FALSE;

                CStdioFile file;
                CString str,str2;
                str=str2=\_T("");
                
                file.Open(\_T("G:\\\\Test.txt"),CFile::modeRead |CFile::typeText ,0);
                
                while(file.end)
                {
                	file.ReadString(str);
                
                	if(!str.Trim().IsEmpty())
                	{
                		if(flag==FALSE)
                		{
                			CStdioFile file1;
                			file1.Open(\_T("G:\\\\final.txt"),CFile::modeCreate|CFile::modeWrite|CFile::typeText ,0);
                			file1.Seek(0,CFile::end);
                			file1.WriteString(str);
                			file1.WriteString(\_T("\\n"));
                			file1.Close();
                			flag=TRUE;
                		}
                		if(file\_read\_write(str)==FALSE)
                		{
                			CStdioFile file2;
                			file2.Open(\_T("G:\\\\final.txt"),CFile::modeWrite|CFile::typeText ,0);
                			file2.Seek(0,CFile::end);
                			file2.WriteString(str);
                			file2.WriteString(\_T("\\n"));
                			file2.Close();			
                
                		}
                
                	}
                	else if(str.Trim().IsEmpty())
                	{
                		break;
                	}
                }
                file.Close();
                
                ShellExecute(NULL,\_T("open"),\_T("G:\\\\final.txt"),NULL,NULL,SW\_SHOW);
                
                BOOL file\_read\_write(CString string);
                

                BOOL Ctest::file_read_write(CString string)
                {
                BOOL flag=FALSE;
                CStdioFile file;
                CString str1;
                str1=_T("");

                file.Open(\_T("G:\\\\final.txt"),CFile::modeRead |CFile::typeText ,0);
                
                while(file.end)
                {
                	file.ReadString(str1);				
                
                	if(!str1.Trim().IsEmpty())
                	{
                		if(\_tcscmp(string,str1)==0)
                		{
                			flag=TRUE;
                			break;
                		}
                	}
                	else
                	{
                		break;
                	}
                	
                
                }
                file.Close();
                
                if(flag==TRUE)
                {
                	return TRUE;
                }
                else
                {
                	return FALSE;
                }
                

                }

                To accomplish great things, we must not only act, but also dream; not only plan, but also believe.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups