[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to substitute in a string for the first n matches?
From: |
Denis Shirokov |
Subject: |
Re: How to substitute in a string for the first n matches? |
Date: |
Wed, 31 Mar 2021 14:13:11 +0300 |
if you want to process large data the you must have to use a
pointer - not an string as the source but the pointer:
func repn( ptr, regexp, n, rep ,currpos,A ) {
currpos = 1
"" in A
while ( n-- > 0 && match( substr( _SOURCE[ ptr ], currpos
), regexp ) ) {
A[ length( A ) ] = substr( _SOURCE[ ptr ], currpos,
RSTART - 1 ) rep
currpos += RSTART + RLENGTH - 1 }
return _reta( A ) }
the source should be stored in _SOURCE[ ptr ] before repn() will be
calling. the ptr may be an any
string.
but for gawk the most effective way will be:
func repn( t, regexp, n, rep ,T,D ) {
if ( patsplit( t, T, regexp, D ) ) {
for ( t = 1; t <= n; t++ )
T[ t ] = rep
return _retab( T, D ) }
return t }
you can find implementation of the function _reta() (and not the
only) in include file
_arr.mod. the file is available to download from
https://github.com/digics/gawklib.
just include its at any point of your gawk project. the library
isn't requiring any
initializations. small documentation file for this library is
also present in _arr.rtf.
check out the performance part of the documentation.
Good Luck!
kind Regards
Denis
- Re: How to substitute in a string for the first n matches?, (continued)
- Re: How to substitute in a string for the first n matches?, david kerns, 2021/03/26
- Re: How to substitute in a string for the first n matches?, arnold, 2021/03/29
- Re: How to substitute in a string for the first n matches?, arnold, 2021/03/29
- Re: How to substitute in a string for the first n matches?, Wolfgang Laun, 2021/03/29
- Re: How to substitute in a string for the first n matches?, Peng Yu, 2021/03/29
- Re: How to substitute in a string for the first n matches?, Wolfgang Laun, 2021/03/29
- Re: How to substitute in a string for the first n matches?, arnold, 2021/03/29
- Message not available
- Message not available
- Message not available
- Message not available
- Re: How to substitute in a string for the first n matches?,
Denis Shirokov <=