|
Answer» Hey all,
Usually I'm answering others but was wondering if I could get a little help on something I've been working on. I've got a batch file that displays two columns of information, and it's fairly easy to get that to work with spacing and everything. What I'm wanting to do is make it so that I don't chop words at all, like most word PROCESSORS. Obviously there is no set size for the data or this would be a simple task, and I know what I need to do and how to do it, but was more looking for if there was a way to make it more efficient. Here is what I have, the VARIABLES are fairly self explanatory I hope:
Code: [Select]:setdisplay set taskline1=Description: %taskdesc:~0,16% set goalline1=Description: %goaldesc:~0,16% set taskcut=29 set goalcut=29 :task1loop call set taskcheck=%%taskline1:~!taskcut!,1%% if "taskcheck"==" " (goto task2loop) set /a taskcut-=1 goto task1loop ...
So this goes on and basically sets 6 lines of text for these descriptions without cutting words appart (spacing is taken care of seperately). What I am wanting is to know if there is a way that I can make this more efficient? I've been racking my brain on it now for a while so I'm hoping another set of eyes will help to get past the mental block I'm having.
Thanks.Have you considered hyphenation? Hyphens | Punctuation Rules
That would work, except when there is a space at the end of the line, then it would just look goofy. Since I would have to go through the testing phase for that, I might as well make it look as good as possible.Hi Raven, I am really visual person. I kind of need to see what your input looks like and what you expect the output to look like.Essentially there are going to be two columns displayed on the page that have info from a data file. The description is the only one that I'm worried about as it is likely to be the only thing that requires multiple lines. In the end, I would like the display to look something like this:
Code: [Select]Task ID: 4 /Goal ID: 1 Description: Grab serial /Description: Create the numbers of the printers in /Reports part of this program The front office and do the /to include reports of tasks paperwork to get rid of them./active, completed, etc. / Notice that there are no broken words (as there would be the way the program was set ORIGINALLY.) This is what the program is going to end up doing, I'm just looking for a more efficient way of doing it.Alright, so have been trying to be as efficient as possible on this one, and have hit a non-working roadblock. Trying to use the for /l to assign multiple lines in as few lines of code as possible. I've looked it over again and again, and I don't see what is going wrong. I think it has to do with when the variables are being expanded, but when ran, I get multiple "The syntax of the command is incorrect." Anybody know what the deal is?
Code: [Select]for /f "usebackq" %%a in (`linecut.bat 0 16 "%taskdes%"`) do (set length=%%a) call set taskline1=Description: %taskdes:~0,^%length%% set offset=%length% for /l %%b in (2,1,6) do ( set length=29 for /f "usebackq" %%F in (`linecut.bat !offset! !length! "%taskdes%"`) do (set length=%%F) call set taskline%%b=%taskdes:~^!offset!,^!length!% set /a offset=!offset!+!length! ) %taskdes% is set earlier in the script and is a description of the task. Below is the linecut.bat file that is being UTILIZED:
Code: [Select]echo off
set offset=%1 set length=%2 set textline=%3 echo %offset% | findstr /i [a-z] if errorlevel 1 (goto loop) else ( set length=0 goto end ) echo %length% | findstr /i [a-z] if errorlevel 1 (goto loop) else ( set length=0 goto end ) :loop call set textcut=%%textline:~^%offset%,%length%%% if not "%textcut:~-1,1%"=="" ( if not "%textcut:~-1,1%"==" " ( set /a length-=1 goto loop ) ) set /a length-=1 :end echo %length% exit I'm stumped. So any help would be great. Thanks.
|