Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

OPI_LR2011_ch2m1

.pdf
Скачиваний:
7
Добавлен:
07.02.2016
Размер:
1.35 Mб
Скачать

61

3.' +: CompareOrdinal, CompareTo, Substring.

4.' +: Concat, CopyTo, ToCharArray.

5.' +: 2, EndsWith, ToLower.

6.' +: Equals, Insert, ToUpper.

7.' +: Format, LastIndexOf, Trim.

8.' +: Intern, PadLeft, TrimEnd.

9.' +: Join, PadRight,

TrimStart.

10.' +: Chars, Remove, Insert.

3.3.3/+ .

3.3.4@ .

3.4 !4 #"4

3.4.1= .

3.4.2.

3.4.39 .

3.4.49 , \ - ( ^ .

3.4.5@, \

(5 Y. ), ( ( ^ -

.

3.5 6^ 4 # 7 2

3.5.1• + ?

3.5.2• + ?

3.5.3• + + ?

3.5.4• + Y ?

62

3.5.5StringBuilder?

3.5.6« »?

3.5.7< -

.

3.5.8?

3.5.9«+»?

3.5.10<

.

3.5.119 ^ (

?

3.5.12• ^

?

3.5.13• ] ?

3.5.14• ^] ?

3.5.15' Match .

63

4 B 9 9 9 B 4 9 B r C

4.1 5 7

@ + \ Visual Studio.

4.2 " 4 5 5 7K 4 "43 ! 4

9 ( ]

. 1 Y -

. 8 ( ,

– . 2# ]

.

4.2.1 A 2 2 84"

@ + ( . ' - ^] + ] +

. ' ^ Y + ( -

+. ' ^ -

, , Y . ¡ ^] +,

^ +. +

+, Y

+.

/ + 2# ]

File, FileStream StreamReader. 9 File ,

, , +. 9 FileStream -

+ +. /']

^^ . ] (

.

h + ']

FileStream +. /

File ] ( ' ']), ]

^ File. /

'] FileStream:

64

FileStream mystream = File.Open(":\Myfile.txt", FileMode.Open, FileAccess.Read);

+-

^ C# StreamReader StreamWriter. @ ^ ,

, . StreamReader StreamWr t r '^

^ :

StreamReader reader = new StreamReader (mystream) ;

StreamWriter writer = new StreamWriter(mystream);

4.2.2 7 7 "438 7 2 < 64"

' + ( ( -

+ +. ( -

FileMode.Open, \ ] +, \ ]; FileAccess.Read, \ ]

( +. 8 Open ] ']

FileStream, ^ ^

+.

4.2.34 6 17 "438 7 2 # 5 5s5 2 < 64"

< . 4.1

+. h ( + -

^ OpenFileDialog SaveFileDialog. @

(. h ( + -

Y '] OpenFileDialog

ShowDialog. ' FileName ] '

+ Y .

, Y , \

] +, + ^

+.

2 Fileapp. ' -

Text + «= ». ' + -

Textbox :

Text – «»;

Multiline – True;

Dock – Fill.

65

? 4.1 – h +

' Textbox . @-

Multiline ] , -

Dock ] ( +. • \ -

Dock Fill, ^ \ +.

' + MainMenu. 2

«8» «@» « ».

Name «@» « » menuItemOpen menuItemSave. 2 ^ - ^ «@» « ». Y ,

Y ( Y -

^. '

menuItemOpen_Click menuItemSave_Click.

h + OpenFileDialog SaveFileDialog. h Filter «Text files (*.txt)!*.txt». {

], \ + Y-

«txt».

66

^ ( + ,

(:

private void menuItemOpen_Click (object sender, System.EventArgs e) {

//PQ^\< TP _ SRY Z^ qPl ^

OpenFileDialog1.ShowDialog();

//Zt^\< T<' qPl ^

string filename = OpenFileDialog1.FileName;

// ST ZRSP\< qPl hR P l P iTk\< Q R< T

FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);

//j qPl ST ZR Rl if(stream != null) {

//S Zk\< Y'\ StreamReader T P iTk\<

//l _ Q ST ZR R< <

StreamReader reader = new StreamReader(stream);

//hR P\< S [ qPl T QP R ^\< S TextBox textBox1.Text = reader.ReadToEnd();

//QP ZRSP\< qPl

stream.Close();

}

}

private void menuItemSave_Click (object sender, System.EvantdArgs e) {

//PQ^\< TP _ SRY Z^ qPl ^

SaveFileDialog1.ShowDialog();

//Zt^\< T<' qPl ^

string filename = SaveFileDiaiog1.FileName;

// ST ZRSP\< qPl QP R ^ l P iTk\< Q T< T

FileStreem.stream = File.Open (filename, FileMode.Create, FileAccess.Write);

//j qPl ST ZR Rl if(stream != null) {

//S Zk\< Y'\ Streamwriter T P iTk\<

//l _ Q ST ZR R< <

StreamWriter writer = new StreamWriter(stream);

//QP R ^\< P T S T writer.Write(textBox1.Text);

//Z R< P T Q ^ ^ qPl writer.Flush();

//QP ZRSP\< qPl stream.Close();

}

}

h . ?

+ ] 6 :

+;

+ ;

StreamReader;

67

;

TextBox;

+.

+ ( 6 :

+;

+ ;

StreamWriter;

;

;

+.

. / . , \ -

( . 4.1) +. ' /9

+ . +. <-

^ . , \ , ' +, \ +. '

+. @ ( ,

Y ^ «S».

4.3 "3 2 3 7

4.3.1/

^ , ^ , ( -

.

4.3.2@ +.

4.3.3@ , -

4 3 : ( -

+. ' ( - + + .

1.( ^ , ^ -

+. ' -

( ( .

2.( ^ , ^ -

+. ' -

( ( .

3.( ^ , ^ -

^ +, \ Y-

, ] +. '

68

( (

.

4.( ^ , ^ -

+ ^

+. ' (

( .

5.( ^ , ^ -

+. ' -

( ( ^ -

+.

6.( ^ , ^ -

+ ^

+. ' (

( ^ +.

4.3.4/+ .

4.3.5@ .

4.4 !4 #"4

4.4.1= .

4.4.2.

4.4.39 .

4.4.49 , \ - ( ^ .

4.4.5@, \

(5 Y. ), ( ( ^ -

.

4.5 6^ 4 # 7 2

4.5.1€ + ?

4.5.2• ] +

2#?

4.5.3' '] File-

stream.

4.5.4• ^ +?

69

4.5.5• ( +

+?

4.5.6• +?

4.5.7• +?

4.5.8• + Visual Studio BC++?

4.5.9• \ +?

4.5.10€ ( +?

4.5.11• ^ -

( +?

4.5.12• + ] '

+ Y

4.5.13• Y + -

+ ?

4.5.14• ^] \ + ?

4.5.15• ^] StreamReader?

70

9 @9

1. ¢ @.@. 2 2 ( Windows / @. @. ¢. – : ¡, 2003. – 385 .

2. h( S. / } Microsoft Visual Studio .Net 2003 /

S. h(. – : ? , 2003. – 463 .

3. S Y h. C# ( / h. S Y. – : S£</ ¢ , 2005. – 467 .

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]