Build abbreviations for underscore separated strings

Help with writing and playing macros

Build abbreviations for underscore separated strings

Postby pablo.villamil » Thu Mar 29, 2012 10:58 am

Hello, I need help with a macro please.
I have lines with the character underscore [_]. I need to paste at the end of the line the first character follow by each character after an underscore like that:

Before macro
TEMPORAL_COMPORTAMIENTO_CAR
TEMPORAL_FORMULAS_CAR
TERMINALES_ATM_POS_TARJ
TIPO_CAMBIOS_CONT
TIPO_CHEQUES_CUE
TIPO_COL_DET_GEN
TIPO_COLUMNAS_GEN
TIPO_COMP_CONT
TIPO_FILAS_GEN
TIPO_FORMULAS_CAR
TIPO_GASTOS_CAJAS_CHICAS_CAJ
TIPO_INGRESOS_RENTAS_PER

After macro
TEMPORAL_COMPORTAMIENTO_CAR=TCC
TEMPORAL_FORMULAS_CAR=TFC
TERMINALES_ATM_POS_TARJ=TAPT
TIPO_CAMBIOS_CONT=TCC
TIPO_CHEQUES_CUE=TCC
TIPO_COL_DET_GEN=TCDG
TIPO_COLUMNAS_GEN=TCG
TIPO_COMP_CONT=TCC
TIPO_FILAS_GEN=TFG
TIPO_FORMULAS_CAR=TFC
TIPO_GASTOS_CAJAS_CHICAS_CAJ=TGCCC
TIPO_INGRESOS_RENTAS_PER=TIRP

Thanks a lot for your help!
pablo.villamil
Newbie
 
Posts: 2
Joined: Thu Mar 29, 2012 9:47 am

Re: Build abbreviations for underscore separated strings

Postby Mofi » Thu Mar 29, 2012 12:14 pm

Because of your detailed before and after example it was easy for me to write this little macro using tagged expressions within a loop to produce the required result.

The macro property Continue if search string not found must be checked for this macro.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase RegExp "%^(?^)^(*_*^)$"
Replace All "^1^2=^1"
Loop
Find MatchCase RegExp "%^(*^)_^(?^)^(*^)$"
Replace All "^1!#!^2^3^2"
IfNotFound
ExitLoop
EndIf
EndLoop
Find MatchCase "!#!"
Replace All "_"

The 2 occurrences of character sequence !#! in the macro can be replaced also by a single character like ! or # or & which surely never exists in the file to make this macro even faster as it already is.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Build abbreviations for underscore separated strings

Postby pablo.villamil » Thu Mar 29, 2012 12:32 pm

Mofi thank you very much!!!
The macro is working!
I will read about tagged expressions to learn about it.
pablo.villamil
Newbie
 
Posts: 2
Joined: Thu Mar 29, 2012 9:47 am


Return to Macros