{"id":1392,"date":"2008-09-02T23:09:00","date_gmt":"2008-09-02T14:09:00","guid":{"rendered":"https:\/\/hdmr.org\/d\/?e=111"},"modified":"2008-09-02T23:09:00","modified_gmt":"2008-09-02T14:09:00","slug":"blogn-111","status":"publish","type":"post","link":"https:\/\/hdmr.org\/d\/?e=111","title":{"rendered":"CSV\u3092\u5fe0\u5b9f\u306b\u6b63\u898f\u8868\u73fe\u306f\u8aad\u3081\u307e\u3059\u304b?"},"content":{"rendered":"<p>\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u3067\u4fbf\u5229\u306b\u3084\u3063\u3066\u304f\u308c\u308b\u30af\u30e9\u30b9\u3092\u81ea\u4f5c\u3057\u3066\u307e\u3057\u305f\u3002<br \/>System.ComponentModel.Component\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3059\u308c\u3070\u3044\u3044\u307f\u305f\u3044\u3060\u306d\u3002<br \/>\u8a73\u3057\u304f\u306fMSDN\u3092\u898b\u308c\u3070\u3044\u3044\u3002<br \/><a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/hkasytyf(VS.80).aspx\">\u30a4\u30d9\u30f3\u30c8 \u30d9\u30fc\u30b9\u306e\u975e\u540c\u671f\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u305f\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9 \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0<\/a><br \/>\u307e\u3041\u3057\u304b\u3057\u308f\u304b\u308a\u306b\u304f\u3044\u3002\u5b9f\u969b\u4f5c\u3063\u3066\u307f\u305f\u304c\u9a19\u3055\u308c\u3066\u308b\u6c17\u304c\u3057\u3066\u306a\u3089\u3093\u3002<br \/>\u3051\u3069\u3001GUI\u3092\u958b\u767a\u3059\u308b\u30c7\u30b6\u30a4\u30ca\u30fc\u304b\u3089\u304b\u306a\u308a\u3044\u308d\u3044\u308d\u64cd\u4f5c\u3067\u304d\u308b\u306e\u3067\u3001GUI\u4f5c\u6210\u6642\u306b\u306f\u975e\u5e38\u306b\u4fbf\u5229\u3060\u308d\u3046\u306d\u3002<br \/>\u3053\u306e\u8abf\u5b50\u3067\u3044\u308d\u3044\u308d\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u304b\u3002<\/p>\n<hr \/>\n<p>CSV\u3060\u304c\u3001RFC 4180\u3067\u6a19\u6e96\u5316\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u30c7\u30d5\u30a1\u30af\u30c8\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u3063\u3066\u3084\u3064\u3067\u3059\u306d\u3002<br \/>\u6a19\u6e96\u304c\u3042\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u307e\u308b\u3093\u3058\u3083\u306a\u304f\u3066\u3001\u6a19\u6e96\u304c\u4f5c\u3089\u308c\u3066\u3044\u304f\u3068\u3044\u3046\u3053\u3068\u306d\u3002<br \/>CSV\u3068\u3044\u3046\u306e\u306f\u3044\u308d\u3044\u308d\u306a\u6d41\u5100\u304c\u3042\u308a\u307e\u3059\u3002\u3060\u304b\u3089\u73fe\u5b9f\u306b\u6cbf\u3063\u3066\u3044\u308b\u304b\u306f\u3061\u3087\u3063\u3068\u308f\u304b\u308a\u307e\u305b\u3093\u3002\u3051\u3069\u4e00\u5fdc\u3053\u308c\u3092\u57fa\u6e96\u306b\u8003\u3048\u307e\u3057\u3087\u3046\u3002<br \/>\u3053\u308c\u306b\u3088\u308c\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u898f\u5247\u3067\u3059\u3002<br \/>\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308a\u3001\u30ec\u30b3\u30fc\u30c9\u306fCR+LF\u3067\u533a\u5207\u308b\u3001\u30ec\u30b3\u30fc\u30c9\u306e\u6700\u5f8c\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5f8c\u306b\u30ab\u30f3\u30de\u306f\u4ed8\u3051\u306a\u3044<br \/>\u30ab\u30f3\u30de\u30fbCR+LF\u30fb\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c8\u3092\u542b\u3080\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u56f2\u3080 <br \/>\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c8\u306f\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c82\u3064\u3067\u30a8\u30b9\u30b1\u30fc\u30d7\u3059\u308b<br \/>\u307e\u3041\u6b63\u76f4\u3053\u306e\u7a0b\u5ea6\u3067\u6e08\u3080\u306e\u3060\u304b\u3089\u512a\u3057\u3044\u898f\u683c\u306a\u3093\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>CSV\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u306e\u306f\u305d\u3093\u306a\u306b\u96e3\u3057\u304f\u306a\u3044\u3051\u3069\u3001\u8aad\u307f\u8fbc\u3080\u306e\u306f\u5c11\u3057\u8003\u3048\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3002<br \/>\u307e\u3041\u3001\u30ab\u30f3\u30de\u3068CR+LF\u3067\u533a\u5207\u308b\u3060\u3051\u306a\u3089\u7c21\u5358\u306a\u3093\u3067\u3059\u3051\u3069\u306d\u3002<\/p>\n<hr \/>\n<p>\u3055\u3066\u3001\u5b9f\u969b\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u3068\u3044\u3046\u306e\u3060\u304c\u3001\u3053\u3046\u306a\u308a\u305d\u3046\u3002<\/p>\n<pre>my @match=( $data=~m\/(?:([^,\\n\"]*)(\\n|,)|(?<=,)([^,\\n\"]*)()|\"((?:\"\"|[^\"])*)\"(\\n|,|))\/g );<br \/>my $row=[];<br \/>my @csv=();<br \/>while(@match){<br \/>  my($a,$b,$c,$d,$e,$f)=map{shift(@match)}(1..6);<br \/>  my $field=$a\/\/$c\/\/$e;<br \/>  $field=~ s\/\"\"\/\"\/g;<br \/>  push(@$row,$field);<br \/>  if(($b\/\/$d\/\/$f) ne ','){ push(@csv,$row); $row=[]; }<br \/>}<\/pre>\n<p>\u975e\u5e38\u306b\u8907\u96d1\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002\u539f\u56e0\u306f\u6700\u7d42\u30ec\u30b3\u30fc\u30c9\u306e\u5f8c\u306bCR+LF\u306f\u5165\u308c\u3066\u3082\u5165\u308c\u306a\u304f\u3066\u3082\u3044\u3044\u3068\u3044\u3046\u3053\u3068\u3002<br \/>\u3053\u306e\u73cd\u5999\u306a\u6b63\u898f\u8868\u73fe\u3060\u3051\u3069\u30013\u3064\u306e\u6761\u4ef6\u306e\u30de\u30c3\u30c1\u3092\u540c\u6642\u306b\u884c\u3063\u3066\u3044\u308b\u3002<br \/>\u5f8c\u65b9\u53c2\u7167\u3057\u306a\u3044(?:\uff5e)\u306e\u30b0\u30eb\u30fc\u30d7\u5316\u3067\u308f\u304b\u308a\u306b\u304f\u3044\u304c\u3001\u307e\u3041\u305d\u3046\u3044\u3046\u3082\u3093\u3067\u3059\u3002<br \/>([^,\\n&#8221;]*)(\\n|,)\u3068(?<=,)([^,\\n\"]*)()\u3068\"((?:\"\"|[^\"])*)\"(\\n|,|))\u306e3\u3064\u306e\u6761\u4ef6\u3067\u3059\u3002<br \/>1\u3064\u76ee\u306e\u6761\u4ef6\u306f\u57fa\u672c\u7684\u306a\u3053\u3068\u3002\u30ab\u30f3\u30de\u30fb\u6539\u884c\u30fb\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c8\u3092\u542b\u307e\u306a\u3044\u6587\u5b57\u304c\u5ef6\u3005\u3068\u7d9a\u3044\u3066\u3001\u30ab\u30f3\u30de\u304b\u6539\u884c\u3067\u7d42\u308f\u308b\u3002<br \/>2\u3064\u76ee\u306e\u6761\u4ef6\u306f\u6700\u7d42\u30ec\u30b3\u30fc\u30c9\u306e\u5f8c\u306bCR+LF\u3092\u5165\u308c\u306a\u3044\u5834\u5408\u306e\u51e6\u7406\u3002<br \/>(?<=,)\u3068\u306f\u30de\u30c3\u30c1\u3059\u308b\u3068\u3053\u308d\u76f4\u524d\u306f\u30ab\u30f3\u30de\u3068\u3044\u3046\u610f\u5473\u3002<br \/>\u3068\u3053\u308d\u3067\u8907\u6570\u30de\u30c3\u30c1\u306e\u3068\u304d\u3001\u30de\u30c3\u30c1\u3057\u305f\u3089\u3001\u6b21\u306f\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u306e\u6b21\u304b\u3089\u6761\u4ef6\u306b\u5f53\u3066\u306f\u307e\u308b\u304b\u898b\u3066\u56de\u308b\u3002<br \/>\u4eca\u56de\u306e\u6761\u4ef6\u306f\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5f8c\u306e\u30ab\u30f3\u30de\u306f\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u306b\u542b\u307e\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3059\u3067\u306b\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u3082\u898b\u3066\u3082\u3089\u3046\u3068\u3002<br \/>\u307e\u3041\u5358\u7d14\u306b\u3001\u524d\u304c\u30ab\u30f3\u30de\u3067\u3042\u308b\u3068\u3044\u3046\u524d\u63d0\u3067\u8a71\u3092\u3059\u308b\u3068\u3068\u3044\u3046\u98a8\u306b\u8aad\u3081\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\u305d\u306e\u3068\u304d\u306f\u6539\u884c\u3084\u30ab\u30f3\u30de\u306f\u56de\u53ce\u3057\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br \/>\u3068\u3053\u308d\u3067|\u3067\u3044\u304f\u3064\u304b\u306e\u6761\u4ef6\u3092\u4e26\u3079\u305f\u3068\u304d\u306f\u524d\u304b\u3089\u8a55\u4fa1\u3055\u308c\u308b\u306e\u3088\u306d\u3002<br \/>\u3082\u30571\u3064\u76ee\u306e\u6761\u4ef6\u3067\u30de\u30c3\u30c1\u3059\u308c\u3070\u3001\u6539\u884c\u304b\u30ab\u30f3\u30de\u306f\u56de\u53ce\u3055\u308c\u3066\u3001<br \/>\u6539\u884c\u304b\u30ab\u30f3\u30de\u304c\u7121\u304b\u3063\u305f\u304c\u305f\u3081\u306b\u5f53\u3066\u306f\u307e\u3089\u306a\u304b\u3063\u305f\u3068\u304d\u3060\u30512\u3064\u76ee\u306e\u6761\u4ef6\u306b\u5408\u3046\u304b\u3068\u3044\u3046\u8a71\u306b\u306a\u308b\u3002<br \/>\u306a\u306e\u3067\u5909\u306a\u611f\u3058\u3060\u304c\u3046\u307e\u304f\u3044\u304f\u3002<br \/>3\u3064\u76ee\u306f\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c8\u3067\u56f2\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u3001&#8221;&#8221;\u30682\u3064\u7d9a\u304f\u304b\u3001&#8221;\u4ee5\u5916\u306e\u6587\u5b57\u304c\u9023\u7d9a\u3059\u308b\u90e8\u5206\u3092\u56de\u53ce\u3059\u308b\u3002<\/p>\n<hr \/>\n<p>\u3055\u3066\u3001\u4eca\u56de\u306e\u30de\u30c3\u30c1\u7d50\u679c\u3060\u304c\u3001$1\u306b1\u3064\u76ee\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3001$2\u306b1\u3064\u76ee\u306e\u30ab\u30f3\u30de\u304b\u6539\u884c\u2026\u3068\u3044\u3046\u98a8\u306b\u5165\u308b\u3002<br \/>\u5f53\u3066\u306f\u307e\u3089\u306a\u304b\u3063\u305f\u3082\u306e\u306fundef\u306b\u306a\u308b\u3002<br \/>\u3057\u304b\u3082\u8907\u6570\u30de\u30c3\u30c1\u3067\u3053\u308c\u304c\u3072\u305f\u3059\u3089\u30ea\u30b9\u30c8\u306b\u5165\u308b\u3002<br \/>(&#8216;yamamoto&#8217; , &#8216;,&#8217; , undef , undef , undef , undef , undef , undef , &#8216;100&#8217; , &#8221; , undef , undef)<br \/>\u975e\u5e38\u306b\u308f\u304b\u308a\u306b\u304f\u3044\u3002\u307e\u3041Perl\u306e\u30ea\u30b9\u30c8\u306e\u90fd\u5408\u3067\u3059\u3002<br \/>\u305d\u3053\u3067while\u3067\u30ea\u30b9\u30c8\u304c\u7a7a\u306b\u306a\u308b\u307e\u30676\u3064\u305a\u3064shift\u3057\u3066\u3001\u51e6\u7406\u3057\u3066\u3044\u304f\u3053\u3068\u306b\u3057\u305f\u3002<br \/>map{shift(@match)}(1..6)\u3060\u304c\u3001\u3053\u308c\u306f( shift(@match),shift(@match),shift(@match),shift(@match),shift(@match),shift(@match) )\u3068\u540c\u3058\u610f\u5473\u3002<br \/>map\u306f\u4e0e\u3048\u3089\u308c\u305f\u30ea\u30b9\u30c8(\u4eca\u56de\u306f (1..6) )\u30921\u3064\u305a\u3064\u56de\u3057\u3066\u3001{ }\u5185\u306e\u7d50\u679c\u3067\u30ea\u30b9\u30c8\u3092\u4f5c\u308b\u3068\u3002<br \/>\u4eca\u56de\u306f(1..6)\u306f\u3042\u307e\u308a\u95a2\u4fc2\u306a\u304f\u3066\u3001\u5358\u306bshift(@match)\u30926\u56de\u3057\u305f\u7d50\u679c\u306e\u30ea\u30b9\u30c8\u3092\u53d7\u3051\u53d6\u3063\u3066\u308b\u3060\u3051\u3067\u3059\u3002<br \/>$a\/\/$c\/\/$e\u3082\u898b\u6163\u308c\u306a\u3044\u304c\u3001undef\u5bfe\u7b56\u3067\u3059\u3002<br \/>$a\/\/$c\u306f$a\u304cundef\u3067\u306a\u3051\u308c\u3070$a\u3001undef\u306a\u3089\u3070$c\u3001\u3068\u3044\u3046\u98a8\u306a\u3082\u306e\u3002\/\/\u306f||\u3092\u50be\u3051\u305f\u3082\u306e\u3060\u3068\u8a00\u308f\u308c\u3066\u3044\u308b\u3002<br \/>\u3059\u306a\u308f\u3061$a\u304b$c\u304b$e\u3067\u3069\u308c\u304bundef\u4ee5\u5916\u3068\u3044\u3046\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<br \/>$row\u306f\u30ea\u30b9\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6295\u3052\u8fbc\u3093\u3067\u3001,\u4ee5\u5916\u3067\u533a\u5207\u3089\u308c\u3066\u308b\u306e\u3092\u898b\u305f\u3089\u3001$row\u3092@csv\u306bpush\u3059\u308b\u3002<br \/>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u30ec\u30b3\u30fc\u30c9\u3054\u3068\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30ea\u30b9\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306e\u5165\u3063\u305f\u30ea\u30b9\u30c8@csv\u304c\u5f97\u3089\u308c\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<hr \/>\n<p>Perl\u3067\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u3092C#\u306b\u843d\u3068\u3057\u307e\u3057\u305f\u3002<br \/>C#\u3067\u3082\u6b63\u898f\u8868\u73fe\u3067\u7c98\u3063\u3066\u307e\u3059\u3088\u3002<br \/>\u305f\u3060Perl\u3067\u306f\u6c17\u306b\u3057\u3066\u306a\u304b\u3063\u305f\\r\u306e\u3053\u3068\u3092\u8003\u3048\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3001<br \/>\u305d\u308c\u3068.NET Framework\u3067\u306f(?<1>\uff5e)\u3068\u3059\u308c\u3070$1\u306b\u5165\u308b\u3068\u3044\u3046\u306e\u304c\u3042\u308b\u306e\u3067\u5168\u90e8\u305d\u308c\u3092\u4ed8\u3051\u305f\u3002<br \/>\u3053\u3046\u3044\u3046\u6b63\u898f\u8868\u73fe\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>(?:(?<1>[^,\\r\\n\"]*)(?<2>\\r?\\n|,)|(?<=,)(?<1>[^,\\r\\n\"]*)(?<2>)|\"(?<1>(?:\"\"|[^\"])*)\"(?<2>\\r?\\n|,|))<\/pre>\n<p>\u307e\u3041C#\u306e\u5834\u5408\u6587\u5b57\u5217\u306f&#8221;&#8221;\u3067\u56f2\u3046\u3068\u6c7a\u307e\u3063\u3066\u308b\u306e\u3067&#8221;\u3092\\&#8221;\u306b\u5909\u66f4\u3057\u306a\u3044\u3068\u3044\u304b\u3093\u3051\u3069\u306d\u3002<br \/>\\r\u306e\u3053\u3068\u3092\u8003\u616e\u3057\u3066\u3042\u308a\u307e\u3059\u3002\u305f\u3060CR+LF\u3067\u3082LF\u3067\u3082\u901a\u308b\u306f\u305a\u3002<br \/>\u307e\u3041\u3057\u304b\u3057C#\u3067\u307e\u3067\u6b63\u898f\u8868\u73fe\u3067\u3084\u308b\u304b\u3068\u3044\u3046\u306e\u306f\u3042\u308b\u308f\u306a\u3002<br \/>\u3051\u3069\u304d\u308c\u3044\u3060\u304b\u3089\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u3067\u4fbf\u5229\u306b\u3084\u3063\u3066\u304f\u308c\u308b\u30af\u30e9\u30b9\u3092\u81ea\u4f5c\u3057\u3066\u307e\u3057\u305f\u3002System.ComponentModel.Component\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3059\u308c\u3070\u3044\u3044\u307f\u305f\u3044\u3060\u306d\u3002\u8a73\u3057\u304f\u306fMSDN\u3092\u898b\u308c\u3070\u3044\u3044\u3002\u30a4\u30d9\u30f3\u30c8 \u30d9\u30fc\u30b9\u306e\u975e\u540c\u671f\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1392","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1392"}],"version-history":[{"count":0,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1392\/revisions"}],"wp:attachment":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}