abc 「abc」の文字数は3です C#の文字形式 「C#の文字形式」の文字数は7です 「C#の文字形式」の4番目の文字は「文」です |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*★ String の基礎 前田 稔 ★*/
using System;
class Prog
{
static string str1 = "str1 abc";
static String str2 = "str2 XYZ";
//static string str3 = new String(new char[]{'S','t','r','i','n','g'});
static string str3 = new string(new char[]{'s','t','r','i','n','g'});
public static void Main()
{
Console.WriteLine(str1);
Console.WriteLine(str2);
Console.WriteLine(str3);
Console.ReadLine();
}
}
|
![]()
//★ string と char 前田 稔 ★
using System;
class Prog
{
public static void Main()
{
char[] chararray = new char[3];
chararray[0] = 'a';
chararray[1] = 'b';
chararray[2] = 'c';
string str;
str = new string(chararray);
Console.WriteLine(str);
int n = str.Length;
Console.WriteLine("「{0}」の文字数は{1}です", str, n);
char[] title = {'C', '#', 'の', '文', '字', '形', '式'};
string strTitle = new string(title);
Console.WriteLine(strTitle);
n = title.Length;
Console.WriteLine("「{0}」の文字数は{1}です", strTitle, n);
char c = title[3];
Console.WriteLine("「{0}」の4番目の文字は「{1}」です", strTitle, c);
Console.ReadLine();
}
}
|
![]()
//★ char[] ⇔ string 前田 稔 ★
using System;
class Text
{
public static void Main()
{
char[] chr1 = "ABCDefgh".ToCharArray();
string str1 = new string(chr1);
Console.WriteLine(str1);
string str2 = "IJKLMN前田稔";
char[] chr2 = str2.ToCharArray(2,6);
Console.WriteLine("[{0}] のサイズは{1}です", str2,str2.Length);
Console.WriteLine(new string(chr2));
Console.ReadLine();
}
}
|
C:\DATA\C#\BAT\Prog1>Char_Str ABCDefgh [IJKLMN前田稔] のサイズは9です KLMN前田 |
![]()
![]()
[Next Chapter ↓]カンマで区切られた数字を配列に変換
※・ ※・ ※・