[問題] 檔案字串換位

作者: xx250919 (pfnh)   2014-12-30 09:42:21
char.txt內容為
1 2 3
4 5 6
7 8 9
10 11 12
請問我該如何撰寫程式擷取資料讓它變換以下排列並另存檔案
char2.txt
1 2 3 4
5 6 7 8
9 10 11 12
麻煩大大指導,謝謝
作者: shadowjohn (轉角遇到愛)   2014-12-30 10:12:00
先把斷行全換成空白,然後用空白分格轉array改成 i!=0 && i%4==0 斷行或是斷行換成空白,原本斷行的下一個空白改成斷行
作者: mmis1000 (秋月戀楓)   2014-12-30 12:18:00
.replace(/[\r\n\s]+/g, " ").replace(/((?:\d+\s*){3,3}\d+)\s?/g, "$1\n").replace(/(\n+$|^\n+)/g, "")
作者: swijo (熱風)   2014-12-31 13:41:00
選轉成array再用splice去換

Links booklink

Contact Us: admin [ a t ] ucptt.com