Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cut first line from notepad
#1
Hello awesome support !
Qm is very good programm, but when I need to write code without using toolbar I be upset. Thank you for the help which you give me, people help each other so happens very seldom.
I try to write code for my task, but it has turned out just awfully. I won't place him here. If you want help me, I tried to use s.getsel([cut] [format] [control]) for cut from notepad first line (withou opening) to clip board, and delete empty first line.
Like this I need...
We have file with different numbers in different lines (for example 1234):
--------------
1
2
3
4

IF I start macro one time- first line cut, after cut file save, and if we open file we have
-------------
2
3
4
and we have 1 in clipboard

I start macro second time, and we have in file
-------------
3
4
( 2 in clipboard )

I want to bring benefit to you. how I am able to do it?
Thx!
#2
For it you'll need to learn Quick Macros string functions, such as find, str.get, str.remove. Look in the help file.
#3
I tried to use your help-post, but it has turned out here that

Code:
Copy      Help
str s.getfile("C:\Users\User\Desktop\1.txt")
int i
s.getl(s -i)
s.setclip
s.remove(0 999)
to copy the first line is work. But not delete first line and to keep changes in the text file with removed line. How I am able to do it? help please.
#4
Function Macro19
Code:
Copy      Help
;;********************************************************
;;*
;;*
;;* 2 examples about getting a line.
;;* Example 1, get FIRST LINE
;;* Example 2, get THIRD LINE
;;*
;;*
;;********************************************************
;;
;Assuming '1.txt' contains:
;abc
;def
;ghi

;; EXAMPLE 1
str s="$desktop$\1.txt" ;; This is the path to the desktop
str get_text.getfile(s) ;; variable 'get_text' contains the contents of the path in 's'
str first_line.getl(get_text 0)
first_line.setclip ;; put the 'first_line' into clipboard
out first_line


;; EXAMPLE 2 (uses integer variable 'i' to set which line to grab, '2' means 'THIRD' line! ('getl' uses ZERO index, meaning first item = 0  (0,1,2,...))
int i=2
get_text.getfile(s)
str third_line.getl(get_text i)
third_line.setclip
out third_line

;; To GET the clipboard contents
str geclipboard.getclip
out geclipboard


;; If you do NOT understand below explanation, then just do this
;; str s="C:\Users\User\Desktop\1.txt"

;; $desktop$ , is special folder indication for the desktop path in windows
;; if you execute the below, it will output THE FULL ABSOLUTE path of your desktop location:

;;---------
;; str s="$desktop$\1.txt"
;; s.expandpath
;; out s
;;---------

;; Then below in the output pane the FULL path to the desktop will be displayed.
;; You do not have to execute the command "s.expandpath" if you use $-paths
;; only if you need to see/use the full absolute path. QM can process $-paths without having
;; to use .expandpath. BUT YOU MUST USE EXISTING $-paths

;; To see other existing $-Paths which can be used in QM, above in QM in the toolbar
;; in the top right toolbar with pen/hand icon click the 6th icon 'folder with spyglass icon'
;; if you hover over it, shows 'Files/web' click on it, select FIRST item 'Run program',
;; a dialog appears. In the top of that dialog you see a button called 'SF' (somewhere at th top left)
;; click on it and you see all the special folders.
;; If you select 'Cookies' for example, it will fill in the inputfield '$Cookies$\' NOTE THE ENDING BACKSLASH

;; This handy when you compile your macro/function to .exe and then use it on other pc
;; If other pc has different Desktop path, using $Desktop$ will always correctly resolve to
;; correct Desktop path.

;; You can DRAG a textfile into the QM editor and it will automatically create the 'run ...' command
;; and if you drag from a location that has a special folder ($-folder) associated with, in this example
;; you could DRAG the '1.txt' file into the QM editor, it will automatically place: run "$desktop$\1.txt"
#5
Macro Macro21
Code:
Copy      Help
;;********************************************************
;;*
;;*
;;* 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'
#6
I assume because of the amount of work must be put in, in the next version of QM Gintaras can not explain everything regarding the basic functions, some things require some extensive research/trial and error (best way to learn!)
My explanation might not be the best way but it might be a start.

Note that on the forum there is an string function str.RemoveLine, found here: replace line
But before using pre made functions maybe it is best to try to approach this using existing member functions if you are starting QM.
If you understand those basic member functions then you can try to use the functions on the QM forum.
#7
Huge thanks to you r0n for your post! Your explanations for me more clear than the text from ContextHelp. I understand that it is does not matter how many symbols in the line, QM will count everything of them
Can you to prompt me, if I need to edit the file 1.txt , by your code, from №1 to №2 how it wil be look?
№1
ABC
DEF
GHI

A B C [ ] D E F [ ] G H I
0 1 2 3 4 5 6 7 8 9 10 11 12

№2
DEF
GHI
D E F [ ] G H I
0 1 2 3 4 5 6 7
I need to use code like this
Code:
Copy      Help
str s="$desktop$\1.txt"
str get_text.getfile(s)
str getline
int line_pos=getline.getl(get_text 0) ;; '0' and we have first LINE,'
out line_pos ;; This should output 0

get_text.remove(line_pos getline.len)
;;* and somehow to delete empty line in "memory" and save new text (without empty line) in file
#8
Macro Macro22
Code:
Copy      Help
str s="$desktop$\1.txt"
str get_text.getfile(s)
str getline
int line_pos=getline.getl(get_text 0) ;; CHANGE THE NUMBER HERE TO THE LINE YOU WANT TO GET, '0'= first line, '1' = second line...etc...
get_text.remove(line_pos getline.len)
get_text.trim ;; trim removes leading and trailing spaces, (put cursor on "trim" in QM editor then press [F1])
out get_text

;; At line 4 you see '0' this means GET the line at line '0' (FIRST LINE!), we store it in 'getline'
;; At line 5 you remove the exact length (amount of characters) of 'getline', we remove starting at 'line_pos' which should be '0'
;; line_pos will be '0' at 'A' and this will be put into variable 'line_pos' at line 4, do NOT confuse this with the zero in .=> getl(get_text 0)

It is confusing in beginning, keep re-studying the examples (in this forum thread and the help file). You will get it.


Forum Jump:


Users browsing this thread: 3 Guest(s)