Jump to content


Windows Server 2012

- - - - -

C# ҹ¨ҡ file ѧ䧤


  • Please log in to reply
28 replies to this topic

#1 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 03 January 2006 - 05:22 PM

¹ code ҳ

// Read the file and display it line by line.
System.IO.StreamReader file =
   new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
   Console.WriteLine (line);

}

file.Close();


ǾҤҨҡ file ʴ label ѹá
label.Text="Ѵ" Ẻ ͡¹Ф
ͧ code ç˹

#2 tsubasa

tsubasa

    Star

  • Star
  • 864 posts

Posted 03 January 2006 - 06:00 PM

ͧ encoding ͹ new StreamReader ٹФѺ
System.Text.Encoding encoder = System.Text.Encoding.ASCII;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt",encoder);


#3 massacre

massacre

    Newbie

  • Members
  • Pip
  • 27 posts

Posted 04 January 2006 - 09:32 AM

TextReader setup = new StreamReader(Application.StartupPath+"\\setup.ini",Encoding.Default);

#4 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 04 January 2006 - 09:57 AM

tsubasa, on Jan 3 2006, 07:00 PM, said:

ͧ encoding ͹ new StreamReader ٹФѺ
System.Text.Encoding encoder = System.Text.Encoding.ASCII;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt",encoder);

<{POST_SNAPBACK}>


ѹ ????? ᷹ ͧ  UTF7 , UTF8 , Unicode ͧǡ

Quote

TextReader setup = new StreamReader(Application.StartupPath+"\\setup.ini",Encoding.Default);

setup 价õͤ  ͧ using ͻǤ

#5 bpitk

bpitk

    Member

  • Members
  • PipPip
  • 223 posts

Posted 04 January 2006 - 11:59 AM

for your code,as above(or something liked this)
// Read the file and display it line by line.
System.IO.StreamReader file 
     = new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null) 
     Console.WriteLine (line);
file.Close();
Your system Command -prompt can use Thai-font?   :blink:
(or Not? Have you ever tried to show Thai-char on it by another way?)

Edited by bpitk, 04 January 2006 - 06:22 PM.


#6 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 04 January 2006 - 12:40 PM

ͧ label.Text="Ѵ" Ẻ ͡Ф
ԴҹҨǡѺҹҡ font file AngsanaUPC Ǵ

Command -prompt   (dir Ǫҹ͡)
ͧѧѹͤ
ѹǡѹѧ䧤 :huh:

#7 Nine_Biz-Talk.Net

Nine_Biz-Talk.Net

    Member

  • Members
  • PipPip
  • 131 posts

Posted 04 January 2006 - 02:20 PM

Function ѹ Convert Encode ͧ Text File
System Encode (Windows Code Page) ͧѺ
ͧʹ Text file ѹ Encode
͡ ԡŧ¤Ѻ


   using System.Text;
   using System.IO;
   ...........................

   public string textFileReader(string pathFileName)
   {
     string line;
     StreamReader fs;
     try 
     {
        fs = new StreamReader(pathFileName);
        line = fs.ReadToEnd();

        /* ҹ Encode ҡ String ҹҡ text file */ 
        Encoding encodeSource = Encoding.GetEncoding(fs.CurrentEncoding.CodePage);
        fs.Close();

        //* ............ */
        Encoding systemEncode = Encoding.Default; 
        Encoding targetEncode = encodeSource;

        /*  getbyte array ҡ string ҹ */
        byte[] srcData = systemEncode.GetBytes( line );
        byte[] dstData;

        /*  Encode ҧѹ windows  text file  Convert byte array  text file encode */
        if( targetEncode != systemEncode )
          dstData = Encoding.Convert( systemEncode, targetEncode, srcData );
        else 
          dstData = srcData;

        /* convert bytearray  string  text file encode */
        return  targetEncode.GetString(dstData);

     }
     catch(Exception ex)
     {
        throw new IOException("cannot find " + pathFileName,ex);
     }

   }

˹¤ѺҨ code ͡ ѴٻẺ ФѺ ˹ ҹ Space ͧ˹¨ѧ  ;)   :wacko:  :wacko:


.......

Edited by Nine_Biz-Talk.Net, 04 January 2006 - 05:03 PM.


#8 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 04 January 2006 - 04:47 PM

ͺسҡ ͧٹФ

#9 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 04 January 2006 - 05:00 PM

ͧǤ ͷѹѧ ??????
÷ͧ价ͻǤ ͧ set áѺкͻ

ͧ¹ code Ẻ

public static void loadTopicFromFile()
{
	thaiTopic=new  ArrayList();
	engTopic=new  ArrayList();
	
	string line;

	System.IO.StreamReader file = new System.IO.StreamReader("c:\\engTopic.txt");
	Encoding encodeSource = Encoding.GetEncoding(file.CurrentEncoding.CodePage);
	Encoding systemEncode = Encoding.Default; 
	Encoding targetEncode = encodeSource;
	while((line = file.ReadLine()) != null)
	{
	/*  getbyte array ҡ string ҹ */
	byte[] srcData = systemEncode.GetBytes( line );
	byte[] dstData;

	/*  Encode ҧѹ windows  text file   Convert byte array  windows encode */
	if( targetEncode != systemEncode )
            dstData = Encoding.Convert( systemEncode, targetEncode, srcData );
	else 
            dstData = srcData;

	/* convert bytearray  string  windows encode */
	string yesStr=  targetEncode.GetString(dstData);
	engTopic.Add(yesStr);
  
	}
	file.Close();
}


#10 Nine_Biz-Talk.Net

Nine_Biz-Talk.Net

    Member

  • Members
  • PipPip
  • 131 posts

Posted 04 January 2006 - 05:28 PM

ͧ觨ҡ

Quote

while((line = file.ReadLine()) != null)



     line = file.ReadToEnd();

١͹¤Ѻ  ͨ繻ѭҷ Encode String Ф Ƿҧա


???    ;)
...

Edited by Nine_Biz-Talk.Net, 04 January 2006 - 05:30 PM.


#11 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 04 January 2006 - 05:41 PM

ͧǤ copy method س Nine_Biz-Talk.Net ¹¤
string ʴ label  ѹ ????
set label1.Text="Ѵ";  ẺѹѧФ
ͧس Nine_Biz-Talk.Net set ç˹觤

#12 Nine_Biz-Talk.Net

Nine_Biz-Talk.Net

    Member

  • Members
  • PipPip
  • 131 posts

Posted 04 January 2006 - 06:04 PM

ѧҡ

Quote

  System.IO.StreamReader file = new System.IO.StreamReader("c:\\engTopic.txt");
  Encoding encodeSource = Encoding.GetEncoding(file.CurrentEncoding.CodePage);

ͧ Return ٤ҹ˹¹ФѺ  

   return "System Encode Name = " + Encoding.Default.EncodingName.ToString() + 
      " Encode Page = " + Encoding.Default.CodePage.ToString() + Environment.NewLine + 
      "Text File Encode Name = " + encodeSource.EncodingName.ToString() + 
      " Encode Page = " + encodeSource.CodePage.ToString();


Ѿͧ
System Encode Name = Thai (Windows) Encode Page = 874
Text File Encode Name = Unicode (UTF-8) Encode Page = 65001

ͧ Set Region Setting
Tab á ͡ Thai Thailand ӴѺ
Tab 2 Ҷ١çͧá ͵Դ
Tab 3 ͡ Thai ç Language for non unicode

Ѻ

Edited by Nine_Biz-Talk.Net, 04 January 2006 - 06:11 PM.


#13 bpitk

bpitk

    Member

  • Members
  • PipPip
  • 223 posts

Posted 04 January 2006 - 06:29 PM

ͧ winhex Դ
c:\engTopic.txt
c:\test.txt
ǤѴ͡(ҧǹ)˹ԤѺ
byte by byte ͧ in Hex (ҹ16)ѹáѹ
(֧ encode - decode ҡѧ)

#14 Nine_Biz-Talk.Net

Nine_Biz-Talk.Net

    Member

  • Members
  • PipPip
  • 131 posts

Posted 04 January 2006 - 09:12 PM

س gib ҧ Text File ѧ¤Ѻ
ҡ .NET ͻ Ҩҡк

#15 gib

gib

    Junior Member

  • Members
  • Pip
  • 83 posts

Posted 05 January 2006 - 09:28 AM

Nine_Biz-Talk.Net, on Jan 4 2006, 07:04 PM, said:

Ѿͧ
System Encode Name = Thai (Windows) Encode Page = 874
Text File Encode Name = Unicode (UTF-8) Encode Page = 65001

Ѿ͹ѹ¤

..ҧ notpad ҹФ ͻǤ
java ҹ ¤ԴҹҨ




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users