" 12.3, 3.14, 2.718, 4.567, 8.7654 " 12.3 3.14 2.718 4.567 8.7654 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
static string str = " 12.3, 3.14, 2.718, 4.567, 8.7654 ";
static char[] delimiter = { ',' }; //分割文字
static float[] tbl = new float[10];
|
public static int Main()
{
string[] wk;
wk= str.Split(delimiter); //カンマで分割
for(int i=0; i<wk.GetLength(0); i++)
{
tbl[i]= float.Parse(wk[i]);
Console.WriteLine(tbl[i]);
}
Console.ReadLine();
return 0;
}
|
float val = 3.14f; Console.WriteLine(val.ToString()); |
static string str = "1,2,11,12,33,32,31,123";
static int[] tbl = new int[10];
string[] wk;
wk= str.Split(new char[] {',', ' '}); //カンマまたは空白で分割
for(int i=0; i<wk.GetLength(0); i++)
{
tbl[i]= int.Parse(wk[i]);
Console.WriteLine(tbl[i]);
}
|
/*★ 配列 ⇒ string 前田 稔 ★*/
using System;
class Prog
{ public static void Main()
{ int[] ary = new int[]{ 1, 5, 2 };
string str = String.Join(",", ary);
Console.WriteLine(str);
Console.ReadLine();
}
}
|
C:\DATA\C#\BAT>w.exe 1,5,2 |
![]()
[Previous Chapter ↑]カンマで区切られた数字を配列に変換
※・ ※・