Csharp/CSharp Tutorial/String/Chars in String — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 15:16, 26 мая 2010

Creating Strings from char array

<source lang="csharp">using System; class MainClass {

 static void Main(string[] args)
 {
   char[] MyChar2 = {"H","e","l","l","o","\0"};
   char[] MyChar3 = new char[6];
   MyChar3[0] = "H";
   MyChar3[1] = "e";
   MyChar3[2] = "l";
   MyChar3[3] = "l";
   MyChar3[4] = "o";
   MyChar3[5] = "\0";
   
   Console.WriteLine(MyChar3);
   Console.WriteLine(MyChar2);
 }

}</source>

Display a string, one char at a time

<source lang="csharp">using System;

class MainClass {

 public static void Main() {   
   string str1 = "ABCDEabcde1234567890";   
   
   Console.WriteLine("Display str1, one char at a time."); 
   for(int i=0; i < str1.Length; i++)  
     Console.Write(str1[i]);   
   Console.WriteLine("\n");   
 }

}</source>

Display str1, one char at a time.
ABCDEabcde1234567890

Getting a char[] from a string

<source lang="csharp">using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; public class MainClass {

   public static void Main()
   {
       string s = "Hello, World.";
       char[] c1 = s.ToCharArray();
       char[] c2 = s.ToCharArray(0, 5);
   }

}</source>