001.
002.
003.
004.
Imports
System.IO
005.
Imports
System.Text
006.
007.
Module
MyModule
008.
009.
010.
011.
012.
013.
Sub
Main()
014.
015.
016.
017.
018.
019.
020.
Dim
SJISFileIn
As
StreamReader =
New
StreamReader(
"readme.txt"
, Encoding.GetEncoding(932) )
021.
022.
Dim
Text1
As
String
= SJISFileIn.ReadToEnd()
023.
024.
SJISFileIn.Close()
025.
SJISFileIn.Dispose()
026.
027.
028.
029.
030.
031.
032.
033.
034.
Dim
UTF8BOM
As
UTF8Encoding =
New
UTF8Encoding(
True
)
035.
036.
Dim
UTF8FileOut
As
StreamWriter =
New
StreamWriter(
"readme_utf8.txt"
,
False
, UTF8BOM )
037.
UTF8FileOut.Write( Text1 )
038.
UTF8FileOut.Close()
039.
UTF8FileOut.Dispose()
040.
041.
042.
043.
044.
045.
046.
047.
Dim
UTF8FileIn
As
StreamReader =
New
StreamReader(
"readme_utf8.txt"
, UTF8BOM )
048.
049.
Dim
Text2
As
String
= UTF8FileIn.ReadToEnd()
050.
051.
UTF8FileIn.Close()
052.
UTF8FileIn.Dispose()
053.
054.
055.
056.
057.
058.
if Text1 = Text2 then
059.
Console.WriteLine(
"SHIFT_JIS から読んだものと、UTF-8 から読んだものは同じです"
)
060.
end if
061.
062.
063.
064.
065.
066.
067.
068.
069.
070.
071.
Dim
UTF8noBOM
As
UTF8Encoding =
New
UTF8Encoding()
072.
073.
Dim
UTF8NFileOut
As
StreamWriter =
New
StreamWriter(
"readme_utf8n.txt"
,
False
, UTF8noBOM )
074.
UTF8NFileOut.Write( Text1 )
075.
UTF8NFileOut.Close()
076.
UTF8NFileOut.Dispose()
077.
078.
079.
080.
081.
082.
083.
084.
Dim
UTF8NFileIn
As
StreamReader =
New
StreamReader(
"readme_utf8n.txt"
, UTF8noBOM )
085.
086.
Dim
Text3
As
String
= UTF8NFileIn.ReadToEnd()
087.
088.
UTF8NFileIn.Close()
089.
UTF8NFileIn.Dispose()
090.
091.
092.
093.
094.
if Text2 = Text3 then
095.
Console.WriteLine(
"UTF8(BOM) から読んだものと、UTF8N から読んだものは同じです"
)
096.
end if
097.
098.
099.
100.
101.
102.
103.
104.
Dim
EUCJP
As
Encoding = Encoding.GetEncoding(51932)
105.
106.
Dim
EUCJPFileOut
As
StreamWriter =
New
StreamWriter(
"readme_eucjp.txt"
,
False
, EUCJP )
107.
EUCJPFileOut.Write( Text3 )
108.
EUCJPFileOut.Close()
109.
EUCJPFileOut.Dispose()
110.
111.
112.
113.
114.
115.
116.
117.
Dim
EUCJPFileIn
As
StreamReader =
New
StreamReader(
"readme_eucjp.txt"
, EUCJP )
118.
119.
Dim
Text4
As
String
= EUCJPFileIn.ReadToEnd()
120.
121.
EUCJPFileIn.Close()
122.
EUCJPFileIn.Dispose()
123.
124.
125.
126.
127.
128.
if Text3 = Text4 then
129.
Console.WriteLine(
"UTF8N から読んだものと、EUC-JP から読んだものは同じです"
)
130.
end if
131.
132.
133.
134.
135.
136.
137.
138.
Dim
UNICODE
As
Encoding = Encoding.
Unicode
139.
140.
Dim
UNICODEFileOut
As
StreamWriter =
New
StreamWriter(
"readme_unicode.txt"
,
False
, UNICODE )
141.
UNICODEFileOut.Write( Text4 )
142.
UNICODEFileOut.Close()
143.
UNICODEFileOut.Dispose()
144.
145.
146.
147.
148.
149.
150.
151.
Dim
UNICODEFileIn
As
StreamReader =
New
StreamReader(
"readme_unicode.txt"
, UNICODE )
152.
153.
Dim
Text5
As
String
= UNICODEFileIn.ReadToEnd()
154.
155.
UNICODEFileIn.Close()
156.
UNICODEFileIn.Dispose()
157.
158.
159.
160.
161.
162.
if Text4 = Text5 then
163.
Console.WriteLine(
"EUC-JPから読んだものと、UNICODE から読んだものは同じです"
)
164.
end if
165.
166.
167.
168.
169.
170.
171.
172.
Dim
SHIFTJIS
As
Encoding = Encoding.GetEncoding(932)
173.
174.
Dim
SHIFTJISFileOut
As
StreamWriter =
New
StreamWriter(
"readme_shiftjis.txt"
,
False
, SHIFTJIS )
175.
SHIFTJISFileOut.Write( Text5 )
176.
SHIFTJISFileOut.Close()
177.
SHIFTJISFileOut.Dispose()
178.
179.
180.
181.
182.
183.
184.
185.
Dim
fs
As
FileStream =
New
FileStream(
"readme_shiftjis.txt"
, FileMode.Open )
186.
Dim
fb
As
Byte
() =
New
Byte
( fs.Length ){}
187.
fs.Read( fb, 0, fs.Length )
188.
189.
Dim
Text6
As
String
= SHIFTJIS.GetString( fb, 0, fs.Length )
190.
fs.Close()
191.
fs.Dispose()
192.
193.
194.
195.
196.
if Text5 = Text6 then
197.
Console.WriteLine(
"StreamReader から読んだものと、FileStream から読んだものは同じです"
)
198.
end if
199.
200.
201.
202.
203.
204.
205.
206.
fb = Encoding.GetEncoding(50222).GetBytes(Text6)
207.
Dim
fso
As
FileStream =
New
FileStream(
"readme_jis.txt"
, FileMode.Create )
208.
fso.Write( fb, 0, fb.Length )
209.
fso.Close()
210.
fso.Dispose()
211.
212.
213.
214.
215.
216.
217.
218.
219.
Dim
ByteCr
As
Byte
() =
New
Byte
() { 13 }
220.
Dim
ByteLf
As
Byte
() =
New
Byte
() { 10 }
221.
222.
223.
Dim
repl
As
String
= Encoding.ASCII.GetString(ByteCr)
224.
225.
226.
Console.WriteLine( Text5.Length )
227.
228.
Text5 = Text5.Replace( repl,
""
)
229.
230.
Console.WriteLine( Text5.Length )
231.
Console.WriteLine(
"-------------------------------------"
)
232.
233.
234.
Dim
separator
As
Char
() = Encoding.ASCII.GetChars(ByteLf)
235.
236.
Dim
lines
As
String
()
237.
238.
239.
lines = Text5.Split( separator )
240.
241.
Dim
cnt
As
Integer
= 0
242.
243.
244.
Dim
line
As
String
245.
For
Each
line
In
lines
246.
cnt += 1
247.
if cnt > 5 then
248.
Exit
For
249.
end if
250.
251.
Console.WriteLine(line)
252.
Next
253.
Console.WriteLine(
"-------------------------------------"
)
254.
255.
256.
257.
258.
Dim
separator2
As
String
= Encoding.ASCII.GetString(ByteLf)
259.
260.
lines = Text5.Split( separator2 )
261.
262.
cnt = 0
263.
264.
265.
For
Each
line
In
lines
266.
cnt += 1
267.
if cnt > 5 then
268.
Exit
For
269.
end if
270.
271.
Console.WriteLine(line)
272.
Next
273.
Console.WriteLine(
"-------------------------------------"
)
274.
275.
276.
277.
278.
279.
lines = Text5.Split( Microsoft.VisualBasic.ControlChars.Lf )
280.
281.
cnt = 0
282.
283.
284.
For
Each
line
In
lines
285.
cnt += 1
286.
if cnt > 5 then
287.
Exit
For
288.
end if
289.
290.
Console.WriteLine(line)
291.
Next
292.
Console.WriteLine(
"-------------------------------------"
)
293.
294.
295.
296.
End
Sub
297.
298.
End
Module