Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


How to word wrap in batch filter_list
Author
Message
RE: How to word wrap in batch #11
One way you could get words is like this:
Code:
@echo off & setlocal enabledelayedexpansion
set s="this. is, a bunch! of words"
call :GetWords 4 %s%
echo !text!
pause > nul & goto :eof

:GetWords
set text=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
)
goto :eof

:GetWordAtIndex
for /f "tokens=%1" %%H in (%2) do ( set text=!text!%%H )

I also once created a function to call that would count the number of chars in a variable. Combine that with this and you would have something that works with a bit of tweaking.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #12
One way you could get words is like this:
Code:
@echo off & setlocal enabledelayedexpansion
set s="this. is, a bunch! of words"
call :GetWords 4 %s%
echo !text!
pause > nul & goto :eof

:GetWords
set text=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
)
goto :eof

:GetWordAtIndex
for /f "tokens=%1" %%H in (%2) do ( set text=!text!%%H )

I also once created a function to call that would count the number of chars in a variable. Combine that with this and you would have something that works with a bit of tweaking.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #13
(03-30-2013, 10:45 PM)ArkPhaze Wrote: One way you could get words is like this:
Code:
@echo off & setlocal enabledelayedexpansion
set s="this. is, a bunch! of words"
call :GetWords 4 %s%
echo !text!
pause > nul & goto :eof

:GetWords
set text=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
)
goto :eof

:GetWordAtIndex
for /f "tokens=%1" %%H in (%2) do ( set text=!text!%%H )

I also once created a function to call that would count the number of chars in a variable. Combine that with this and you would have something that works with a bit of tweaking.

Shite. That's right, you made it.
Congrat'z.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: How to word wrap in batch #14
(03-30-2013, 10:45 PM)ArkPhaze Wrote: One way you could get words is like this:
Code:
@echo off & setlocal enabledelayedexpansion
set s="this. is, a bunch! of words"
call :GetWords 4 %s%
echo !text!
pause > nul & goto :eof

:GetWords
set text=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
)
goto :eof

:GetWordAtIndex
for /f "tokens=%1" %%H in (%2) do ( set text=!text!%%H )

I also once created a function to call that would count the number of chars in a variable. Combine that with this and you would have something that works with a bit of tweaking.

Shite. That's right, you made it.
Congrat'z.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: How to word wrap in batch #15
What I would do here is loop taking and adding one word to a temp variable, until the total string char count is just under the buffer width, then from the original variable that contains the full text, set it to the substring of the index of the char length of the temp string, to the end of the full original text.

So say you calculated that "word word word word word" would be the max number of words, such that the # chars would fit just before the width of the console. That is 24 characters, so the original text variable, say called %originaltext%, I would set to: %originaltext:~24%:

Code:
set originaltext=%originaltext:~24%

And repeat until the full text has been exhausted and the substring is shown to be undefined.

Here is my script for checking the length of a string:
Code:
@echo off
call :GetLength "this is a test"
echo %len%
pause > nul & goto :eof

:GetLength
set str=%1
set len=0
:loop
call set tmp=%%str:~%len%,1%%
if defined tmp (
    set /a len+=1
    goto loop
)
set /a len-=2
goto :eof
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #16
What I would do here is loop taking and adding one word to a temp variable, until the total string char count is just under the buffer width, then from the original variable that contains the full text, set it to the substring of the index of the char length of the temp string, to the end of the full original text.

So say you calculated that "word word word word word" would be the max number of words, such that the # chars would fit just before the width of the console. That is 24 characters, so the original text variable, say called %originaltext%, I would set to: %originaltext:~24%:

Code:
set originaltext=%originaltext:~24%

And repeat until the full text has been exhausted and the substring is shown to be undefined.

Here is my script for checking the length of a string:
Code:
@echo off
call :GetLength "this is a test"
echo %len%
pause > nul & goto :eof

:GetLength
set str=%1
set len=0
:loop
call set tmp=%%str:~%len%,1%%
if defined tmp (
    set /a len+=1
    goto loop
)
set /a len-=2
goto :eof
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #17
I put together a working example out of boredom...
Code:
@echo off & setlocal enabledelayedexpansion
set mode_cols=30
mode %mode_cols%,28

set str="this is a long paragraph of text... Just to see what we can do with this script..."

:begin
    set tmp=!str:"=!
    if "%tmp:~1,1%"==" " (
        set str=%tmp%
        set str="!str:~1!"
    )
    
    set len=0
    set index=1
    :loop
        call :GetWordAtIndex %index% %str%
        if not defined gwat_result (
            echo %str:"=%
            goto end
        )
        call :GetLength "%gwat_result%"
        set /a len+=%gl_result%+1
        set /a total=%len%-1
        if %total% LEQ %mode_cols% (
            set /a index+=1
            goto loop
        )
    set /a index-=1
    call :GetWords %index% %str%
    echo %gw_result%

    call :GetLength "%gw_result%"
    set str=!str:"=!
    set str="!str:~%gl_result%!"
    goto begin
:end

pause > nul & goto :eof

:: ----------------------------
:: arg1: number of words to return
:: arg2: the text
:: returns: %gw_result%
:: ----------------------------
:GetWords
set gw_result=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
    if defined gwat_result (
        set gw_result=!gw_result!!gwat_result!
    )
)
set gw_result=!gw_result:~0,-1!
goto :eof

:: ----------------------------
:: arg1: the token word index
:: arg2: the text
:: returns: %gwat_result%
:: ----------------------------
:GetWordAtIndex
set gwat_result=
for /f "tokens=%1" %%H in (%2) do set gwat_result=%%H

:: ----------------------------
:: arg1: the text
:: returns: %gl_result%
:: ----------------------------
:GetLength
set gl_str=%1
set gl_result=0
:gl_loop
    call set gl_tmp=!gl_str:~%gl_result%,1!
    if defined gl_tmp (
        set /a gl_result+=1
        goto gl_loop
    )
    set /a gl_result-=2
goto :eof

[Image: f3YPtE9.png]

Enjoy.

edit;
IMPORTANT: This forum removes it, but you NEED a space at the end of line 51
Code:
set gw_result=!gw_result!!gwat_result!{SPACE_NEEDS_TO_BE_HERE}
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #18
I put together a working example out of boredom...
Code:
@echo off & setlocal enabledelayedexpansion
set mode_cols=30
mode %mode_cols%,28

set str="this is a long paragraph of text... Just to see what we can do with this script..."

:begin
    set tmp=!str:"=!
    if "%tmp:~1,1%"==" " (
        set str=%tmp%
        set str="!str:~1!"
    )
    
    set len=0
    set index=1
    :loop
        call :GetWordAtIndex %index% %str%
        if not defined gwat_result (
            echo %str:"=%
            goto end
        )
        call :GetLength "%gwat_result%"
        set /a len+=%gl_result%+1
        set /a total=%len%-1
        if %total% LEQ %mode_cols% (
            set /a index+=1
            goto loop
        )
    set /a index-=1
    call :GetWords %index% %str%
    echo %gw_result%

    call :GetLength "%gw_result%"
    set str=!str:"=!
    set str="!str:~%gl_result%!"
    goto begin
:end

pause > nul & goto :eof

:: ----------------------------
:: arg1: number of words to return
:: arg2: the text
:: returns: %gw_result%
:: ----------------------------
:GetWords
set gw_result=
for /l %%G in (1,1,%1) do (
    call :GetWordAtIndex %%G %2
    if defined gwat_result (
        set gw_result=!gw_result!!gwat_result!
    )
)
set gw_result=!gw_result:~0,-1!
goto :eof

:: ----------------------------
:: arg1: the token word index
:: arg2: the text
:: returns: %gwat_result%
:: ----------------------------
:GetWordAtIndex
set gwat_result=
for /f "tokens=%1" %%H in (%2) do set gwat_result=%%H

:: ----------------------------
:: arg1: the text
:: returns: %gl_result%
:: ----------------------------
:GetLength
set gl_str=%1
set gl_result=0
:gl_loop
    call set gl_tmp=!gl_str:~%gl_result%,1!
    if defined gl_tmp (
        set /a gl_result+=1
        goto gl_loop
    )
    set /a gl_result-=2
goto :eof

[Image: f3YPtE9.png]

Enjoy.

edit;
IMPORTANT: This forum removes it, but you NEED a space at the end of line 51
Code:
set gw_result=!gw_result!!gwat_result!{SPACE_NEEDS_TO_BE_HERE}
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: How to word wrap in batch #19
what is xp in the programming world

Reply

RE: How to word wrap in batch #20
(08-27-2013, 12:38 PM)okcharly Wrote: what is xp in the programming world

???

Is this implying that XP is still considered 'good' in today's world? (It's not; it's becoming unsupported like all the previous Windows operating systems before it soon, and it has so many other security issues anyways that are now well known.) Here's the question every beginner programmer asks though. My answer would be, are you a good programmer or a bad one, and what are you trying to do in programming? Only then can we tell how good the *language* is.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: 1 Guest(s)