. 2013
1 .................................................................................................................................................. 4
2 .................................................................................................................................................... 5
2.1 ................................................................................................ 5
2.2 ............................................................................................................................... 5
3 ....................................................................................................................................... 6
4 ............................................................................................................... 7
4.1 #.............................................................................................................................................. 7
5. ....................................................................................................................................................... 18
..................................................................................................................................................... 24
:
1) ;
2)
3) .
, . 5.
. , .
4. :
1) ;
2) ;
3) ;
4) .
4.1 #
. # : char, string, StringBuider Regex. , .
char
char Unicode. # har .Net System. , , , . :
|
|
GetNumericValue | , , -1 . |
GetUnicodeCategory | Unicode-. Unicode , (DecimalDigitNumber), (LetterNumber), (LineSeparator), (LowercaseLetter) .. |
IsControl | true, . |
IsDigit | true, . |
IsLetter | true, . |
IsLetterOrDigit | true, . |
IsLower | true, . |
IsNumber | true, ( ). |
IsPunctuation | true, . |
IsSeparator | true, . |
IsUpper | true, . |
IsWhiteSpace | true, (, , ). |
Parse | ( ). |
ToLower | |
ToUpper |
:
static void Main()
{
try
{
char b = 'B', c = '\x64', d = '\uffff';
Console.WriteLine("{0}, {1}, {2}", b, c, d);
Console.WriteLine("{0}, {1}, {2}", char.ToLower(b), char.ToUpper(c), char.GetNumericValue(d));
char a;
do // , e
{
Console.WriteLine(" : ");
a = char.Parse(Console.ReadLine());
Console.WriteLine(" {0}, {1}, {2}", a, (int)a, char.GetUnicodeCategory(a));
if (char.IsLetter(a)) Console.WriteLine("");
if (char.IsUpper(a)) Console.WriteLine(" ");
if (char.IsLower(a)) Console.WriteLine(" ");
if (char.IsControl(a)) Console.WriteLine(" ");
if (char.IsNumber(a)) Console.WriteLine("");
if (char.IsPunctuation(a)) Console.WriteLine("");
} while (a!= 'e');
}
catch
{
Console.WriteLine(" ");
}
}
Array:
static void Main()
{
char[] a ={ 'm', 'a', '', 'i', 'M', 'u', 'S', '!', '!', '!' };
char [] b=" ".ToCharArray(); //
PrintArray(" :", a);
for (int x=0;x<a.Length; x++)
if (char.IsLower(a[x])) a[x]=char.ToUpper(a[x]);
PrintArray(" :", a);
PrintArray(" b:", b);
Array.Reverse(b);
PrintArray(" b:", b);
|
|
}
static void PrintArray(string line, Array a)
{
Console.WriteLine(line);
foreach(object x in a) Console.Write(x);
Console.WriteLine('\n');
}
. , a.
string
string, Unicode, #. System.String .Net. string - Unicode, .. , , , .
:
1) string s; //
2) string s='' ''; //
3) string s=@''! // @ string,
!!! '' // ,
//
4) string s=new string (' ', 20); // 20
5) int x = 12344556; //
string s = x.ToString(); // string
6) char [] a={'a', 'b', 'c', 'd', 'e'}; //
string v=new string (a); //
7) char [] a={'a', 'b', 'c', 'd', 'e'}; // , : 0
string v=new string (a, 0, 2) // , 2
//
string , . .
Compare | () . . | |
CompareTo | . | |
Concat | . | |
Copy | ||
Empty | , | |
Format | ||
IndexOf, IndexOfAny, LastIndexOf, LastIndexOfAny | . | |
Insert | ||
Join | . . | |
Length | ||
PadLeft, PadRigth | . | |
Remove | ||
Replace | . | |
Split | , . . | |
StartWith, EndWith | true false , . | |
Substring | , | |
ToCharArray | ||
ToLower, ToUpper | ||
Trim, TrimStart, TrimEnd | . |
, , , String.Concat(str1, str2), , , str.ToLower(). .
|
|
static void Main()
{
string str1 =" ";
string str2 = string.Copy(str1);
string str3 = " ";
string str4 = " ";
string strUp, strLow;
int result, idx;
Console.WriteLine("str1: " + str1);
Console.WriteLine(" str1: " +str1.Length);
// str1.
strLow = str1.ToLower();
strUp = str1.ToUpper();
Console.WriteLine(" str1: " +strLow);
Console.WriteLine(" str1: " +strUp);
Console.WriteLine();
// ,
result = str1.CompareTo(str3);
if (result == 0) Console.WriteLine("str1 str3 .");
else if (result < 0) Console.WriteLine("str1 , str3");
else Console.WriteLine("str1 , str3");
Console.WriteLine();
//
result = String.Compare(str3,str4,true);
if (result == 0) Console.WriteLine("str3 str4 .");
else Console.WriteLine("str3 str4 .");
Console.WriteLine();
//
result = String.Compare(str1, 4, str2, 4, 2);
if (result == 0) Console.WriteLine(" str1 str2 ");
else Console.WriteLine(" str1 str2 ");
Console.WriteLine();
// .
idx = str2.IndexOf("");
Console.WriteLine(" : " + idx);
idx = str2.LastIndexOf("");
Console.WriteLine(" : " + idx);
//
string str=String.Concat(str1, str2, str3, str4);
Console.WriteLine(str);
//
str=str.Remove(0,str1.Length);
Console.WriteLine(str);
// ""
str=str.Replace("","");
Console.WriteLine(str);
}
, Split Join.
static void Main()
{
string poems = " ";
char[] div = { ' '}; //
// ,
string[] parts = poems.Split(div);
Console.WriteLine(" : ");
for (int i = 0; i < parts.Length; i++)
Console.WriteLine(parts[i]);
// , |
string whole = String.Join(" | ", parts);
Console.WriteLine(" : ");
Console.WriteLine(whole);
}
. , .
:
static void Main()
{
string poems = " , ...";
char[] div = { ' ', ',', '.'}; //
// ,
string[] parts = poems.Split(div);
Console.WriteLine(" : ");
for (int i = 0; i < parts.Length; i++)
Console.WriteLine(parts[i]);
// ,
string whole = String.Join(" | ", parts);
Console.WriteLine(" : ");
|
|
Console.WriteLine(whole);
}
.
1. , parts .
2. , .
Split , :
static void Main()
{
try
{
int[][] MyArray;
Console.Write(" : ");
int n = int.Parse(Console.ReadLine());
MyArray = new int[n][];
for (int i = 0; i < MyArray.Length; i++)
{
string line = Console.ReadLine();
string[] mas = line.Split(' ');
MyArray[i] = new int[mas.Length];
for (int j = 0; j < MyArray[i].Length; j++)
{
MyArray[i][j] = int.Parse(mas[j]);
}
}
PrintArray(" :", MyArray);
for (int i = 0; i < MyArray.Length; i++) Array.Sort(MyArray[i]);
PrintArray(" ", MyArray);
}
catch
{
Console.WriteLine(" ");
}
}
static void PrintArray(string a, int[][] mas)
{
Console.WriteLine(a);
for (int i = 0; i < mas.Length; i++)
{
foreach (int x in mas[i]) Console.Write("{0} ", x);
Console.WriteLine();
}
}
, . , :
static void Main()
{
try
{
int[][] MyArray;
Console.Write(" : ");
string line= Console.ReadLine()
int n = int.Parse(line.Trim());
MyArray = new int[n][];
for (int i = 0; i < MyArray.Length; i++)
{
line = Console.ReadLine();
line=line.Trim(); //
//
n = line.IndexOf(" ");
while (n > 0)
{
line = line.Remove(n, 1);
n = line.IndexOf(" ");
}
string[] mas = line.Split(' ');
MyArray[i] = new int[mas.Length];
for (int j = 0; j < MyArray[i].Length; j++)
{
MyArray[i][j] = int.Parse(mas[j]);
}
}
PrintArray(" :", MyArray);
for (int i = 0; i < MyArray.Length; i++) Array.Sort(MyArray[i]);
PrintArray(" ", MyArray);
}
catch
{
Console.WriteLine(" ");
}
}
static void PrintArray(string a, int[][] mas)
{
Console.WriteLine(a);
for (int i = 0; i < mas.Length; i++)
{
foreach (int x in mas[i]) Console.Write("{0} ", x);
Console.WriteLine();
}
}
. , , Replace. , str.Replace(" ", " "), , .
string , .. , , . :
string a="";
for (int i = 1; i <= 100; i++) a +="!";
Console.WriteLine(a);
100 :
!
!!
!!!
!!!...!!
. , . , . , StringBuilder.
, , # StringBuilder, System.Text. ( new). :
StringBuilder a =new StringBuilder(); // , 16 // StringBuilder b = new StringBuilder("abcd"); // 100 StringBuilder = new StringBuilder(100);// 100 StringBuilder d = new StringBuilder("abcd", 100);// "bcd", 100 StringBuilder d = new StringBuilder("abcd", 1, 3,100); :
Append | . , , string. | |
AppendFormat | ||
Capacity | . , ArgumentOutOfRangeException | |
Insert | ||
Length | . 0 | |
MaxCapacity | , | |
Remove | ||
Replace | ||
ToString | string | |
Chars | . [] | |
Equals | true, | |
CopyTo | char |
|
|
static void Main()
{
try
{
StringBuilder str=new StringBuilder("");
PrintString(str);
str.Append(" ");
PrintString(str);
str.AppendFormat(" {0:f2} ", 123.456);
PrintString(str);
str.Insert(8, " ");
PrintString(str);
str.Remove(7, 21);
PrintString(str);
str.Replace("", "");
PrintString(str);
StringBuilder str1=new StringBuilder(Console.ReadLine());
StringBuilder str2=new StringBuilder(Console.ReadLine());
Console.WriteLine(str1.Equals(str2));
}
catch
{
Console.WriteLine(" ");
}
}
static void PrintString(StringBuilder a)
{
Console.WriteLine(": "+a);
Console.WriteLine(" " +a.Length);
Console.WriteLine(" "+a.Capacity);
Console.WriteLine(" "+a.MaxCapacity);
Console.WriteLine();
}
. CopyTo.
, :
static void Main()
{
StringBuilder a = new StringBuilder("2*3=3*2");
Console.WriteLine(a);
int k=0;
for (int i = 0; i < a.Length; ++i)
if (char.IsDigit(a[i])) k+=int.Parse(a[i].ToString());
Console.WriteLine(k);
}
. , StringBuilder.
. , . . , .
static void Main()
{
Console.WriteLine(" : ");
StringBuilder a = new StringBuilder(Console.ReadLine());
Console.WriteLine(" : "+a);
for (int i=0; i<a.Length;)
if (char.IsPunctuation(a[i])) a.Remove(i,1);
else ++i;
string str=a.ToString();
string []s=str.Split(' ');
Console.WriteLine(" : ");
for (int i=0; i<s.Length; ++i)
if (s[i][0]==s[i][s.Length-1]) Console.WriteLine(s[i]);
}
. , , .
. : , StringBuilder; , String. , .
I. , s:
x y;
using System;
using System.Text;
namespace ConsoleApplication
{
class Class
{
static void Main()
{
Console.WriteLine(" : ");
StringBuilder a = new StringBuilder(Console.ReadLine());
Console.WriteLine(" : "+a);
Console.WriteLine(" x: ");
char x=char.Parse(Console.ReadLine());
Console.WriteLine(" y: ");
char y=char.Parse(Console.ReadLine());
for (int i=0; i<a.Length; ++i)
if (a[i]==x){a.Insert(i+1,y); ++i;}
Console.WriteLine(" : "+a);
}
}
}
1. , ..
2. , ;
3. y;
4. ;
5. , ;
6. , , , ;
7. x;
8. ;
9. substr;
10. substr1 substr2;
11. ;
12. ;
13. x;
14. ;
15. , ;
16. , ;
17. , (, ).
18. , (, );
19. , .
II. , . .
, .
using System;
using System.Text;
namespace ConsoleApplication
{
class Class
{
static void Main()
{
Console.WriteLine(" : ");
StringBuilder a = new StringBuilder(Console.ReadLine());
Console.WriteLine(" : "+a);
Console.WriteLine(" e : ");
string x=Console.ReadLine();
for (int i=0; i<a.Length;)
if (char.IsPunctuation(a[i]))a.Remove(i,1);
else ++i;
string str=a.ToString();
str=str.Trim();
string []s=str.Split(' ');
Console.WriteLine(" : ");
for (int i=0; i<s.Length; ++i)
if (s[i].IndexOf(x)!=-1) Console.WriteLine(s[i]);
}
}
}
1. , n .
2. , .
3. , .
4. , .
5. , ( ).
6. ( ).
7. ( ).
8. .
9. , , .
10. .
11. .
12. .
13. .
14. -, .
15. , . , , , .
16. , .
17. , n .
18. .
19. .
1. . ., . . . .: , 1997.
2. .., . . : 2 . 4.2: . . .: , 1990.
3. . .: , 1991.
4. . . .: -, 1994.
5. / . . , . ., .. . .: , 1991.
6. .. . : / .. .; . . , . . , . . . - /.: - "", 2002. - 416.
7. . . . : / . . , . . ; . . , . . . - .: . ., 2003. - 341.
8. . . : / . . , . . , . . . - .: - , 2004. - 592.
9. . : . . . - 2- . - .: , 2006. - 640.
10. . . 2007 / . . . - .: -, 2007. - 608. 2 .
11. .. : / . . . - .: , 2002. - 608.
12. . . : / . . . - 3- ., . - .: , 2005. - 511.
13. . . : / . . . - .: , 2004. - 272.