07-07-2017, 03:29 PM
Macro Macro21
;;********************************************************
;;*
;;*
;;* To remove a line, do the following 2 steps
;;*
;;*
;;********************************************************
;STEP 1
;==========================
;If '1.txt' contains
;ABC
;DEF
;GHI
;Assume QM 'sees' it like this
;'ABC[]DEF[]GHI'
;Each [] represents a newline.
;
;A is postion 0, B is position 1,...etc....
;A B C [ ] D
;0 1 2 3 4 5
;
;If we want to remove SECOND line, first find out at which position
;the second line begins, in this example it begins at 'D' which is the 5th position from the left
;Note that the '[' and ']' are also counted starting from 0.
;
;If you run the code below it will output '5'
;;
str s="$desktop$\1.txt"
str get_text.getfile(s)
str getline
int line_pos=getline.getl(get_text 1) ;; '1' means SECOND LINE, here we put the position of line 2 in variable 'line_pos'
out line_pos ;; This should output 5
;STEP 2
;==========================
;Now you can use str.remove
;If you want to remove line 2
get_text.remove(line_pos getline.len)
out get_text
;The .remove function removes starting from 'line_pos' (which is 5) and then removes a specified number of characters
;in this example the amount of characters that is in line 2. Line 2 is stored in 'getline', 'getline.len' is the
;amount of characters in 'getline'