CSV並び替えの方法に「テキスト幅」の追加
CSV並び替えの方法に「テキスト幅」を追加して欲しいです。
具体的には、見た目の幅(全角2、半角1)と、文字数(全角半角ともに1) のどちらか(もしくはさらに、エンコーディングによる物理的なバイト数)を選択できるようになるといいです。
オプションとしては、末尾の空白をカウントしない等があるとさらにいいです。
それではご検討よろしくお願いいたします。
ent 様
いつも EmEditor Professional をお使いいただき、誠にありがとうございます。
ご要望については検討させていただきます。
ところで、カーソル位置にある列を選択して、その列を長さによってソートして新規文書を作成するマクロを作成しましたので、もしよろしければお使いください。
if( !editor.EnableTab ) {
alert( "Please enable tabs" );
Quit();
}
editor.ExecuteCommandByID(4461); // select column
s = document.selection.Text
s = s.split("\n").sort(function(a,b) { return a.length - b.length; }).join('\n');
editor.NewFile();
document.selection.Text = s;
また、各列の最小、最大桁数をカウントしてアウトプット バーに表示するマクロも作成したので、もしよろしければ使ってください。
OutputBar.Clear();
OutputBar.Visible = true;
OutputBar.writeln( "Column Min Max" );
document.selection.SetActivePoint( eePosLogical, 1, 1, false );
x = -1;
col = 1;
while( x != document.selection.GetActivePointX( eePosLogical ) ) {
x = document.selection.GetActivePointX( eePosLogical )
nOldHeadingLines = document.HeadingLines;
document.HeadingLines = 0;
editor.ExecuteCommandByID(4461); // select column
document.HeadingLines = nOldHeadingLines;
s = document.selection.Text
a = s.split("\r\n");
a.pop(); // last element is always empty
sTitle = "";
if( a.length > 0 ) {
sTitle = a[0];
}
min = -1;
max = 0;
for( i = nOldHeadingLines; i < a.length; i++ ) {
if( min == -1 || min > a[i].length ) {
min = a[i].length;
}
if( max < a[i].length ) {
max = a[i].length;
}
}
//OutputBar.writeln( "Column " + col + " - min: " + min + ", max: " + max );
OutputBar.writeln( sTitle + " " + min + " " + max );
xView = document.selection.GetActivePointX( eePosView );
if( xView >= 0x08000000 ) { // last column
break;
}
document.selection.SetActivePoint( eePosView, xView, 1, false );
col++;
}
OutputBar.SetFocus();
どちらも JavaScript です。よろしくお願い申し上げます。マクロありがとうございます。
特に2つ目のものはアウトプットバーの活用方法がわかりとても勉強になりました。
1つ目のマクロは、別ウィンドウに抽出されてからソート結果が表示されますが
これは CSV並び替えに 当該機能がもし実装された場合は 同じウィンドウ内でソートが可能になるものでしょうか。(期待しています)
また、マクロの文字列オブジェクトに対してのlength プロパティは 文字の長さを取得できますが、「文字のByte数」を取得するプロパティや、関数などはございますか?
ひらがなの「あ」を例にとると UTF8の場合には3、ShiftJISの場合には2が取得できる関数です。自動でエンコーディングを判定できなくても、特定のエンコーディングを指定して長さが取得できれば良いのですが。
よろしくお願いいたします。
ent 様
いつも EmEditor Professional をお使いいただき、誠にありがとうございます。
次のバージョンでは、「短い文字列から長い文字列へ並べ替え」、「長い文字列から短い文字列へ並べ替え」コマンドが追加され、他の並べ替えコマンドと同様に、同じウィンドウ内でソートが可能になります。
JavaScript で文字列の長さを UTF-8 として取得する方法は、
https://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript
Shift-JIS として取得する方法は、
https://stackoverflow.com/questions/11453944/how-to-get-the-length-of-japanese-characters-in-javascript
をご参照ください。
よろしくお願い申し上げます。
ent 様
いつも EmEditor Professional をお使いいただき、誠にありがとうございます。
まもなく公開する v14.7.0 beta 1 で「短い文字列から長い文字列へ並べ替え」、「長い文字列から短い文字列へ並べ替え」コマンドが追加されました。
まもなく、 https://emeditorjp.wpengine.com/forums/forum/beta/ のフォーラムで公開されますので、お試しいただけると幸いです。
よろしくお願い申し上げます。
このトピックの投稿: 5