(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Creating Strings from char array
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);
}
}
Display a string, one char at a time
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");
}
}
Display str1, one char at a time.
ABCDEabcde1234567890
Getting a char[] from a string
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);
}
}