@miskox,
You must realize that you don't need to store the offset in each record, because if you add /O switch to the first FINDSTR the result will include it...
Antonio
Desired number of spaces - optimizing the code?
Moderator: DosItHelp
Re: Desired number of spaces - optimizing the code?
Aacini wrote:@miskox,
You must realize that you don't need to store the offset in each record, because if you add /O switch to the first FINDSTR the result will include it...
Antonio
+1
Re: Desired number of spaces - optimizing the code?
If you still want to optimize speed, then you could use one of the following examples.
This creates 150 spaces:
That creates 1024 spaces:
Gimmick: And this code aborts the actual cmd instance and returns -1 under my windows xp home:
penpen
This creates 150 spaces:
Code: Select all
@echo off
setlocal enableDelayedExpansion enableExtensions
set "space= "
set "space=!space: =%space: = %!"
endlocal & set "space=%space%"
echo("%space%"
goto :eof
That creates 1024 spaces:
Code: Select all
@echo off
setlocal enableDelayedExpansion enableExtensions
set "space= "
set "space=!space: =%space: = %!"
set "space=!space: =%space: = %!"
endlocal & set "space=%space%"
echo("%space%"
goto :eof
Gimmick: And this code aborts the actual cmd instance and returns -1 under my windows xp home:
Code: Select all
@echo off
setlocal enableDelayedExpansion enableExtensions
set "space= "
set "space=!space: =%space: = %!"
set "space=!space: =%space: = %!"
endlocal & set "space=%space%"
echo("%space%"
goto :eof
penpen
Re: Desired number of spaces - optimizing the code?
Aacini wrote:@miskox,
You must realize that you don't need to store the offset in each record, because if you add /O switch to the first FINDSTR the result will include it...
Antonio
Very good idea, thanks. I have everything done already so I will think about it - I might use it.
The only problem I see is this: if I manually edit the file then record lengths are not correct so I must reindex the file. Also when I do the reinder I skip 'empty' records.
Saso
Re: Desired number of spaces - optimizing the code?
If you use the :StrLen subroutine to get the length of the edited line (in order to check if the new contents fits in the original line), then you may also use it to get the length of the original line. This way, it is not necessary to store the record length in the file neither...
Antonio
PS - You may generate a variable with 256 spaces without delayed expansion this way:
... and you may write a "recLen" number of spaces without delayed expansion this way:
Antonio
PS - You may generate a variable with 256 spaces without delayed expansion this way:
Code: Select all
set "space= "
for /L %%i in (1,1,8) do call set "space=%%space%%%%space%%"
... and you may write a "recLen" number of spaces without delayed expansion this way:
Code: Select all
call echo %%space:~0,%recLen%%%
Re: Desired number of spaces - optimizing the code?
Aacini wrote:If you use the :StrLen subroutine to get the length of the edited line (in order to check if the new contents fits in the original line), then you may also use it to get the length of the original line. This way, it is not necessary to store the record length in the file neither...
Antonio
Yes! I was thinking about this and came to the same conclusion: FINDSTR /O is very good:
Pros:
- no need to store record offset and record length information at all (record offset gets display with /O, I will get record length with a temporary file)
- if I change/update/modify the file with NOTEPAD I don't need to do anything - everything stays the same - very good. No fear of having bad indexes (record offset and record length sizes).
Cons:
- I have to reprogram everything. But I will do this. This is much better solution. Thank Aacini!
Aacini wrote:
PS - You may generate a variable with 256 spaces without delayed expansion this way:Code: Select all
set "space= "
for /L %%i in (1,1,8) do call set "space=%%space%%%%space%%"
This works, too. Great. Thanks again!
Saso