lreplace - Online Linux Manual PageSection : n
Updated : 7.4
Source : Tcl
Note : Tcl Built-In Commands
NAMElreplace − Replace elements in a list with new elements
SYNOPSISlreplace list first last ?element element ...?
.\}
DESCRIPTIONlreplace returns a new list formed by replacing zero or more elements of list with the element arguments. first and last are index values specifying the first and last elements of the range to replace. The index values first and last are interpreted the same as index values for the command string index, supporting simple index arithmetic and indices relative to the end of the list. 0 refers to the first element of the list, and end refers to the last element of the list. If either first or last is less than zero, it is considered to refer to before the first element of the list. This allows lreplace to prepend elements to list. If either first or last indicates a position greater than the index of the last element of the list, it is treated as if it is an index one greater than the last element. This allows lreplace to append elements to list. \{.ev 2
.\} If last is less than first, then any specified elements will be inserted into the list before the element specified by first with no elements being deleted. The element arguments specify zero or more new elements to be added to the list in place of those that were deleted. Each element argument will become a separate element of the list. If no element arguments are specified, then the elements between first and last are simply deleted.
EXAMPLESReplacing an element of a list with another: % lreplace {a b c d e} 1 1 foo
a foo c d e
Replacing two elements of a list with three: % lreplace {a b c d e} 1 2 three more elements
a three more elements d e
Deleting the last element from a list in a variable: % set var {a b c d e}
a b c d e
% set var [lreplace $var end end]
a b c d
A procedure to delete a given element from a list: proc lremove {listVariable value} {
upvar 1 $listVariable var
set idx [lsearch -exact $var $value]
set var [lreplace $var $idx $idx]
}
Appending elements to the list; note that end+2 will initially be treated as if it is 6 here, but both that and 12345 are greater than the index of the final item so they behave identically: % set var {a b c d e}
a b c d e
% set var [lreplace $var 12345 end+2 f g h i]
a b c d e f g h i
\{.ev 2
.\}
SEE ALSOlist(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), lset(n), lrange(n), lsort(n), string(n)
KEYWORDSelement, list, replace 0
Johanes Gumabo
Data Size : 13,206 byte
man-lreplace.nBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 3 / 200,689
Visitor ID : :
Visitor IP : 3.145.80.247 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (rof_escape_sequence_block|26|(null)|(null)|-1|141) (parse_manual_page_|249|lreplace.n|283/141|══─}─══|.══─}─══
) (htmlprn|149|lreplace.n|283/141|.══─}─══|.══─}─══
) (rof_escape_sequence|91|lreplace.n|283/142|\}|.\}
) (parse_manual_page_|249|lreplace.n|283/142|\}|.\}
) (rof_escape_sequence|91|lreplace.n|305/159/305/160|\{.ev 2 |\{.ev 2
) (rof_escape_sequence|91|lreplace.n|305/168|\} |.\}
) (parse_manual_page_|249|lreplace.n|305/168|\}|.\}
) (rof_escape_sequence|91|lreplace.n|362/159/362/160|\{.ev 2 |\{.ev 2
) (rof_escape_sequence|91|lreplace.n|362/168|\} |.\}
) (parse_manual_page_|249|lreplace.n|362/168|\}|.\}
)