私はパイプで区切られた多くのフラットファイルを処理し、次のようになります。
John|Smith|01|01|1901|123 Road
'1901'がパイプ( '|')に基づいてこのレコードの5番目のフィールドであることを確認する方法はありますか?
これは非常に便利で、大量のファイルのフィールドを数える必要がなくなります。
Notepad ++ 32ビットを使用して、パイプ区切りフィールドに基づいてフィールド番号を検索します。
Pythonプラグインをインストールします。そうするには:
新しいスクリプトを作成する:メニューから、[プラグイン] → [ Pythonスクリプト]→ [新しいスクリプト]を選択します。
Pipe Position
、[保存]を選択します"""
Notepad++ python script to count field based on delimiter.
Displays a message box based on the cursor position when invoked
"""
from Npp import *
import re
field_delimiter = '|'
current_pos = editor.getCurrentPos()
line_number = editor.lineFromPosition(current_pos)
line_start = editor.positionFromLine(line_number)
line_end = editor.getLineEndPosition(line_number)
line = editor.getTextRange(line_start, line_end)
index = current_pos - line_start
field_number = line.count(field_delimiter, 0, index)
notepad.messageBox("'%s' is field # %d" % (
line.split(field_delimiter)[field_number], field_number + 1))
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加