Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shodan
Posts: 89
Joined: 01 May 2023 01:49

Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#1 Post by shodan » 29 Apr 2024 05:48

See latest version at viewtopic.php?p=69907#p69907
------------------------------------

This was a lot of work !

If it wasn't so late, I think this directly leads to a fast and robust :split function as well !

This substring uses the similar mechanism as the :len function
That is, split the input variable in two, then search which first half has the match
And so one until it is narrowed down to twice the lenght of the search term
Then I have a "sliding window" find the exact location
It gets slower with longer strings, both input and search string
could not test past 4079 characters

see below for the other functions, but this one is the star

Code: Select all

::Usage Call :GetSubstringIndex InputString SearchString StartIndex ... InputStringN SearchStringN StartIndexN  
(does not actually have an output value yet, only %errorlevel% therefore it does not take multiple argument series as stated above)

Code: Select all

::Usage Call :GetSubstringIndex InputString SearchString StartIndex ... InputStringN SearchStringN StartIndexN 
:GetSubstringIndex
set "_GetSubstringIndex_prefix=_GSSI"
set /a _GSSI_StartIndex=%~3
if defined %~1 call set _GSSI_Input=%%%~1%%
if not defined _GSSI_Input set _GSSI_Input=%~1
if defined %~2 call set _GSSI_Search=%%%~2%%
if not defined _GSSI_Search set _GSSI_Search=%~2
Call :len _GSSI_Input _GSSI_Input_len
Call :len _GSSI_Search _GSSI_Search_len
set /a _GSSI_Input_len-=1
set /a _GSSI_min_search=(%_GSSI_Search_len%*2)
setlocal enabledelayedexpansion
:GetSubstringIndex-loop
set /a _GSSI_HalfInputLen=%_GSSI_Search_len%+(%_GSSI_Input_len%/2)
if %_GSSI_HalfInputLen% LEQ %_GSSI_min_search% ( set /a _GSSI_max_search=%_GSSI_StartIndex%+%_GSSI_min_search%+1 & GoTo :GetSubstringIndex-loop2 )
set /a _GSSI_Middle=%_GSSI_StartIndex%+%_GSSI_HalfInputLen%
set /a _GSSI_HalfInputLenPLUSSearchLenMINUSOne=%_GSSI_HalfInputLen%+%_GSSI_Search_len%-1
set "_GSSI_FirstHalf=!_GSSI_Input:~%_GSSI_StartIndex%,%_GSSI_HalfInputLenPLUSSearchLenMINUSOne%!
set "_GSSI_SecondHalf=!_GSSI_Input:~%_GSSI_Middle%,%_GSSI_HalfInputLen%!
set "_GSSI_FirstResult=!_GSSI_FirstHalf:%_GSSI_Search%=!"
set "_GSSI_SecondResult=!_GSSI_SecondHalf:%_GSSI_Search%=!"
if !_GSSI_FirstHalf! NEQ !_GSSI_FirstResult! ( set /a _GSSI_Input_len=%_GSSI_HalfInputLen% & GoTo :GetSubstringIndex-loop )
if !_GSSI_SecondHalf! NEQ !_GSSI_SecondResult! ( set /a _GSSI_StartIndex=%_GSSI_Middle% & GoTo :GetSubstringIndex-loop )
set /a _GSSI_StartIndex=-1 & GoTo :GetSubstringIndex-end
:GetSubstringIndex-loop2
set "_GSSI_FinalSearch=!_GSSI_Input:~%_GSSI_StartIndex%,%_GSSI_Search_len%!
set /a "_GSSI_debug_remain_len=%_GSSI_max_search%-%_GSSI_StartIndex%"+1
if !_GSSI_FinalSearch! EQU !_GSSI_Search! GoTo :GetSubstringIndex-end
set /a _GSSI_StartIndex+=1
if %_GSSI_StartIndex% LEQ %_GSSI_max_search% GoTo :GetSubstringIndex-loop2
set /a _GSSI_StartIndex=-1
:GetSubstringIndex-end
endlocal & Call :ClearVariablesByPrefix %_GetSubstringIndex_prefix% _GetSubstringIndex_prefix & exit /b %_GSSI_StartIndex%
Simple replace function, similar to a Mid VB function, you have to specify then len you want to take out of the input string
I just noticed I swapped the position of input and output, this will get harmonized later, but I am too tried right now. Spent all weekend and all night on this !

replace string currently fails at 4079 characters of input string

Code: Select all

::Usage Call :ReplaceString SourceString ReplaceString OutputString StartIndex len

Code: Select all

::Usage Call :ReplaceString SourceString ReplaceString OutputString StartIndex len
:ReplaceString
set "_ReplaceString_prefix=_RS"
setlocal enabledelayedexpansion
if defined %~1 call set _RS_Input=!%~1!
if not defined _RS_Input set _RS_Input=%~1
if defined %~2 call set _RS_Replace=!%~2!
if not defined _RS_Replace set _RS_Replace=%~2
if defined %~3 call set _RS_Output=!%~3!
if not defined _RS_Output set _RS_Output=%~3
set /a _RS_StartIndex=%~4
set /a _RS_len=%~5
set /a _RS_RemainIndex=%_RS_StartIndex%+%_RS_len%
set _RS_Intermetiate=!_RS_Input:~,%_RS_StartIndex%!!_RS_Replace!!_RS_Input:~%_RS_RemainIndex%!
for /f "tokens=1* delims=" %%a in ('echo.!_RS_Intermetiate!') do endlocal & set %_RS_Output%=%%a
Call :ClearVariablesByPrefix %_ReplaceString_prefix% _ReplaceString_prefix & GoTo :EOF
There is a demo function that comes with :GetSubstringIndex
I needed it to generate large and varied test strings
It is fast, but uses the cursed scripting language
I wonder if it works with powershell 1.0

Code: Select all

Call :CreateRandomStringPS [NONUMBERS] [NOUPPERCASE] [NOUPPERCASE] [SPACE] [PUNCTUATION] [NOPOISON] [POISON] [EXTENDED] [CONTROL] [RESET] StringLenght1 OutputVariable1 StringLenght2 OutputVariable2 ... StringLenghtN OutputVariableN

Code: Select all

::Usage Call :CreateRandomStringPS [NONUMBERS] [NOUPPERCASE] [NOUPPERCASE] [SPACE] [PUNCTUATION] [NOPOISON] [POISON] [EXTENDED] [CONTROL] [RESET] StringLenght1 OutputVariable1 StringLenght2 OutputVariable2 ... StringLenghtN OutputVariableN
::You can your CLEAR in front of the switches to clear them
:CreateRandomStringPS
set "_CreateRandomStringPS_prefix=_CRS"
set "_CRS_SetList=NONUMBERS NOUPPERCASE NOLOWERCASE SPACE PUNCTUATION NOPOISON EXTENDED CONTROL NOPOISON POISON"
if "[%~1]" EQU "[RESET]" ( for %%a in (%_CRS_SetList%) do ( set "_CRS_%%a=" ) & shift & GoTo :CreateRandomStringPS )
for %%a in (%_CRS_SetList%) do if "[%%a]" EQU "[%~1]" ( set "_CRS_%%a=true" & shift & GoTo :CreateRandomStringPS ) else ( if "[CLEAR%%a]" EQU "[CLEAR%~1]" ( set "_CRS_%%a=" & shift & GoTo :CreateRandomStringPS ) )
set /a _CRS_Len=%~1
set "_CRS_Output=%~2"
set "_CRS_CurrentSet="
if not defined _CRS_NONUMBERS set "_CRS_CurrentSet=%_CRS_CurrentSet% + 48..57"
if not defined _CRS_NOUPPERCASE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 65..90"
if not defined _CRS_NOLOWERCASE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 97..122"
if defined _CRS_SPACE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 32"
if defined _CRS_PUNCTUATION if not defined _CRS_NOPOISON ( set "_CRS_CurrentSet=%_CRS_CurrentSet% + 33..47 + 58..64 + 91..96 + 123..126" ) else ( set "_CRS_CurrentSet=%_CRS_CurrentSet%+ 35..36 + 39 + 42..47 + 58..59 + 61 + 63..64 + 91..93 + 95..96 + 123 + 125 + 126" )
if defined _CRS_POISON if not defined _CRS_PUNCTUATION  set "_CRS_CurrentSet=%_CRS_CurrentSet% + 33 + 34 + 37 + 38 + 40 + 41 + 60 + 62 + 94 + 124"
if defined _CRS_EXTENDED set "_CRS_CurrentSet=%_CRS_CurrentSet% + 128..255"
if defined _CRS_CONTROL set "_CRS_CurrentSet=%_CRS_CurrentSet% + 0..31 + 127"
for /f "tokens=1* delims=" %%a in ('powershell -command "-join (1..%_CRS_Len% | ForEach-Object { %_CRS_CurrentSet:~3% | Get-Random } | ForEach-Object { [char]$_ })" 2^>nul') do set %_CRS_Output%=%%a
if "[%~3]" NEQ "[]" if "[%~4]" NEQ "[]" ( shift & shift & GoTo :CreateRandomStringPS )
Call :ClearVariablesByPrefix %_CreateRandomStringPS_prefix% _CreateRandomStringPS_prefix & GoTo :EOF

Here is the test file, it is ready to go , will execute GetSubstringIndex-DEMO function automatically
It will generate various string arrays
Then apply a "TEST" pattern to each string, at a different index
Then it will read this index and display it.
You know it works when index and result are the same value

Each test is 4 steps
string creation
array population (here result will always read zero)
then SubstringIndex runs with expanded variables
then it runs with byref variable

If you want to see what that looks like
see this video https://youtu.be/jgFjzF_ODGE
GetSubstringIndex-DEMO.zip
(2.71 KiB) Downloaded 1020 times
Last edited by shodan on 30 Apr 2024 03:23, edited 1 time in total.

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#2 Post by shodan » 29 Apr 2024 17:31

New version of

Works to 8155 characters with byref input string, now supports byref parameters for either or both or none input and replace string

Still breaks on poison characters

Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED 8155 testvar

::Usage Call :ReplaceString InputString ReplaceString OutputString StartIndex len
:ReplaceString
set "_ReplaceString_prefix=_RS"
Call :ClearVariablesByPrefix _RS_byref
setlocal enabledelayedexpansion
if defined %~1 set "_RS_byref_input=true"
if defined %~2 set "_RS_byref_replace=true"
set _RS_Output=%~3
set /a _RS_StartIndex=%~4 2>nul
set /a _RS_len=%~5 2>nul
if not defined _RS_StartIndex set /a _RS_StartIndex=0
if not defined _RS_len call :len _RS_len
set /a _RS_RemainIndex=%_RS_StartIndex%+%_RS_len%
if defined _RS_byref_input if defined _RS_byref_replace GoTo :ReplaceString-both-byref-skip
if defined _RS_byref_input if not defined _RS_byref_replace GoTo :ReplaceString-input-byref-skip
if not defined _RS_byref_input set _RS_Input=%~1
if defined not _RS_byref_input if defined _RS_byref_replace GoTo :ReplaceString-replace-byref-skip
if not defined _RS_byref_replace set _RS_Replace=%~2
set _RS_Intermetiate=!_RS_Input:~,%_RS_StartIndex%!!_RS_Replace!!_RS_Input:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-both-byref-skip
set _RS_Intermetiate=!%~1:~,%_RS_StartIndex%!!%~2!!%~1:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-replace-byref-skip
set _RS_Intermetiate=!_RS_Input:~,%_RS_StartIndex%!!%~2!!_RS_Input:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-input-byref-skip
if not defined _RS_byref_replace set _RS_Replace=%~2
set _RS_Intermetiate=!%~1:~,%_RS_StartIndex%!!_RS_Replace!!%~1:~%_RS_RemainIndex%!
:ReplaceString-end
if "[%~6]" NEQ "[]" (shift & shift & shift & shift & shift & GoTo :ReplaceString)
for /f "tokens=1* delims=" %%a in ('echo.!_RS_Intermetiate!') do endlocal & set %_RS_Output%=%%a
Call :ClearVariablesByPrefix %_ReplaceString_prefix% _ReplaceString_prefix & GoTo :EOF

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#3 Post by shodan » 30 Apr 2024 03:22

Improved version of the functions

This now works with strings at least 8100 characters long

Mostly works with everything that doesn't contain poison characters

New extensive test setup is very effective at finding any remaining bugs !

See function GetSubstringIndex-demo at the bottom and ready to use included .bat in the zip file
GetSubstringIndex-DEMO.zip
(4.6 KiB) Downloaded 997 times
When run it will generate a teststring of increasing complexity and insert at every index position the word TEST and try to find it
single letter, then random alphanumeric, then random alphanumeric and punctuation minus poison then that plus extended characters
Also with increase lenght of string
Then it will repeat the teststring patterns but also change the TEST pattern to increasingly complex random character sets





::Usage Call :GetSubstringIndex InputString SearchString StartIndex Optional OutputIndexVar ... InputStringN SearchStringN StartIndexN Optional OutputIndexVar

Code: Select all

::Usage Call :GetSubstringIndex InputString SearchString StartIndex Optional OutputIndexVar ... InputStringN SearchStringN StartIndexN Optional OutputIndexVar
:GetSubstringIndex
set "_GetSubstringIndex_prefix=_GSSI"
Call :ClearVariablesByPrefix _GSSI
set _GSSI_Input=%~1
set _GSSI_Search=%~2
set /a _GSSI_StartIndex=%~3 2>nul
if not defined _GSSI_StartIndex set /a _GSSI_StartIndex=0
setlocal enabledelayedexpansion
if defined %_GSSI_Search% set _GSSI_Search=!%_GSSI_Search%!
set "_GSSI_Input_Pointer=_GSSI_Input"
if defined !_GSSI_Input! (
 set "_GSSI_Input_Pointer=%_GSSI_Input%" 
 )
Call :len "%_GSSI_Input_Pointer%" _GSSI_Input_len
if defined "%_GSSI_Search%" Call :len "%_GSSI_Search%" _GSSI_Search_len
if not defined "%_GSSI_Search%" Call :len _GSSI_Search _GSSI_Search_len
set /a _GSSI_Input_len-=1
set /a _GSSI_min_search=(%_GSSI_Search_len%*2)
:GetSubstringIndex-loop
set /a _GSSI_HalfInputLen=%_GSSI_Search_len%+(%_GSSI_Input_len%/2)
if %_GSSI_HalfInputLen% LEQ %_GSSI_min_search% ( 
	set /a _GSSI_max_search=%_GSSI_StartIndex%+%_GSSI_min_search%+1 & GoTo :GetSubstringIndex-loop2 
	)
set /a _GSSI_Middle=%_GSSI_StartIndex%+%_GSSI_HalfInputLen%
set /a _GSSI_HalfInputLenPLUSSearchLenMINUSOne=%_GSSI_HalfInputLen%+%_GSSI_Search_len%-1
set _GSSI_FirstHalf=!%_GSSI_Input_Pointer%:~%_GSSI_StartIndex%,%_GSSI_HalfInputLenPLUSSearchLenMINUSOne%!
set _GSSI_SecondHalf=!%_GSSI_Input_Pointer%:~%_GSSI_Middle%,%_GSSI_HalfInputLen%!
set _GSSI_FirstResult=!_GSSI_FirstHalf:%_GSSI_Search%=!
set _GSSI_SecondResult=!_GSSI_SecondHalf:%_GSSI_Search%=!
if !_GSSI_FirstHalf! NEQ !_GSSI_FirstResult! ( set /a _GSSI_Input_len=%_GSSI_HalfInputLen% & GoTo :GetSubstringIndex-loop )
if !_GSSI_SecondHalf! NEQ !_GSSI_SecondResult! ( set /a _GSSI_StartIndex=%_GSSI_Middle% & GoTo :GetSubstringIndex-loop )
set /a _GSSI_StartIndex=-1 & GoTo :GetSubstringIndex-end
:GetSubstringIndex-loop2
set _GSSI_FinalSearch=!%_GSSI_Input_Pointer%:~%_GSSI_StartIndex%,%_GSSI_Search_len%!
if !_GSSI_FinalSearch! EQU !_GSSI_Search! GoTo :GetSubstringIndex-end
set /a _GSSI_StartIndex+=1
if %_GSSI_StartIndex% LEQ %_GSSI_max_search% GoTo :GetSubstringIndex-loop2
set /a _GSSI_StartIndex=-1 & GoTo :GetSubstringIndex-end
:GetSubstringIndex-end
if "[%~7]" NEQ "[]" ( shift & shift & shift & shift & shift & GoTo :GetSubstringIndex )
endlocal & Call :ClearVariablesByPrefix %_GetSubstringIndex_prefix% _GetSubstringIndex_prefix & exit /b %_GSSI_StartIndex%
::Usage Call :ReplaceString InputString ReplaceString optional OutputString optional StartIndex optional len

Code: Select all

::Usage Call :ReplaceString InputString ReplaceString optional OutputString optional StartIndex optional len
:ReplaceString
set "_ReplaceString_prefix=_RS"
Call :ClearVariablesByPrefix _RS_byref
setlocal enabledelayedexpansion
if defined %~1 set "_RS_byref_input=true"
if defined %~2 set "_RS_byref_replace=true"
set _RS_Input=%~1
set _RS_Replace=%~2
set _RS_Output=%~3
if not defined _RS_Output set _RS_Output=%_RS_Input%
set /a _RS_StartIndex=%~4 2>nul
if not defined _RS_StartIndex set /a _RS_StartIndex=0
set /a _RS_len=%~5 2>nul
if not defined _RS_len call :len _RS_Replace _RS_len
set /a _RS_RemainIndex=%_RS_StartIndex%+%_RS_len%
if defined _RS_byref_input if defined _RS_byref_replace GoTo :ReplaceString-both-byref-skip
if defined _RS_byref_input if not defined _RS_byref_replace GoTo :ReplaceString-input-byref-skip
if defined not _RS_byref_input if defined _RS_byref_replace GoTo :ReplaceString-replace-byref-skip
set _RS_Intermetiate=!_RS_Input:~,%_RS_StartIndex%!!_RS_Replace!!_RS_Input:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-both-byref-skip
set _RS_Intermetiate=!%_RS_Input%:~,%_RS_StartIndex%!!%_RS_Replace%!!%_RS_Input%:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-replace-byref-skip
set _RS_Intermetiate=!_RS_Input:~,%_RS_StartIndex%!!%_RS_Replace%!!_RS_Input:~%_RS_RemainIndex%!
GoTo :ReplaceString-end
:ReplaceString-input-byref-skip
if not defined _RS_byref_replace set _RS_Replace=%~2
set _RS_Intermetiate=!%_RS_Input%:~,%_RS_StartIndex%!!_RS_Replace!!%_RS_Input%:~%_RS_RemainIndex%!
:ReplaceString-end
if "[%~6]" NEQ "[]" (shift & shift & shift & shift & shift & GoTo :ReplaceString)
for /f "tokens=1* delims=" %%a in ('echo.!_RS_Intermetiate!') do endlocal & set %_RS_Output%=%%a
Call :ClearVariablesByPrefix %_ReplaceString_prefix% _ReplaceString_prefix & GoTo :EOF
::Usage Call :CreateRandomStringPS [NONUMBERS] [NOUPPERCASE] [NOUPPERCASE] [SPACE] [PUNCTUATION] [NOPOISON] [POISON] [EXTENDED] [CONTROL] [RESET] StringLenght1 OutputVariable1 StringLenght2

Code: Select all

::Usage Call :CreateRandomStringPS [NONUMBERS] [NOUPPERCASE] [NOUPPERCASE] [SPACE] [PUNCTUATION] [NOPOISON] [POISON] [EXTENDED] [CONTROL] [RESET] StringLenght1 OutputVariable1 StringLenght2 OutputVariable2 ... StringLenghtN OutputVariableN
::You can your CLEAR in front of the switches to clear them
:CreateRandomStringPS
set "_CreateRandomStringPS_prefix=_CRS"
set "_CRS_SetList=NONUMBERS NOUPPERCASE NOLOWERCASE SPACE PUNCTUATION NOPOISON EXTENDED CONTROL NOPOISON POISON"
if "[%~1]" EQU "[RESET]" ( for %%a in (%_CRS_SetList%) do ( set "_CRS_%%a=" ) & shift & GoTo :CreateRandomStringPS )
for %%a in (%_CRS_SetList%) do if "[%%a]" EQU "[%~1]" ( set "_CRS_%%a=true" & shift & GoTo :CreateRandomStringPS ) else ( if "[CLEAR%%a]" EQU "[CLEAR%~1]" ( set "_CRS_%%a=" & shift & GoTo :CreateRandomStringPS ) )
set /a _CRS_Len=%~1
set "_CRS_Output=%~2"
set "_CRS_CurrentSet="
if not defined _CRS_NONUMBERS set "_CRS_CurrentSet=%_CRS_CurrentSet% + 48..57"
if not defined _CRS_NOUPPERCASE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 65..90"
if not defined _CRS_NOLOWERCASE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 97..122"
if defined _CRS_SPACE set "_CRS_CurrentSet=%_CRS_CurrentSet% + 32"
if defined _CRS_PUNCTUATION if not defined _CRS_NOPOISON ( set "_CRS_CurrentSet=%_CRS_CurrentSet% + 33..47 + 58..64 + 91..96 + 123..126" ) else ( set "_CRS_CurrentSet=%_CRS_CurrentSet%+ 35..36 + 39 + 42..47 + 58..59 + 61 + 63..64 + 91..93 + 95..96 + 123 + 125 + 126" )
if defined _CRS_POISON if not defined _CRS_PUNCTUATION  set "_CRS_CurrentSet=%_CRS_CurrentSet% + 33 + 34 + 37 + 38 + 40 + 41 + 60 + 62 + 94 + 124"
if defined _CRS_EXTENDED set "_CRS_CurrentSet=%_CRS_CurrentSet% + 128..255"
if defined _CRS_CONTROL set "_CRS_CurrentSet=%_CRS_CurrentSet% + 0..31 + 127"
for /f "tokens=1* delims=" %%a in ('powershell -command "-join (1..%_CRS_Len% | ForEach-Object { %_CRS_CurrentSet:~3% | Get-Random } | ForEach-Object { [char]$_ })" 2^>nul') do set %_CRS_Output%=%%a
if "[%~3]" NEQ "[]" if "[%~4]" NEQ "[]" ( shift & shift & GoTo :CreateRandomStringPS )
Call :ClearVariablesByPrefix %_CreateRandomStringPS_prefix% _CreateRandomStringPS_prefix & GoTo :EOF

Code: Select all

:GetSubstringIndex-demo

Call :ClearVariablesByPrefix _GetSubstringIndex

set _GetSubstringIndex_show_string=true

set /a _GetSubstringIndex_index=0
REM set /a _GetSubstringIndex_index=1
REM set /a _GetSubstringIndex_index=2
REM set /a _GetSubstringIndex_index=3
REM set /a _GetSubstringIndex_index=4
REM set /a _GetSubstringIndex_index=5
REM set /a _GetSubstringIndex_index=6
REM set /a _GetSubstringIndex_index=7
REM set /a _GetSubstringIndex_index=8
REM set /a _GetSubstringIndex_index=9
REM set /a _GetSubstringIndex_index=10
REM set /a _GetSubstringIndex_index=11
REM set /a _GetSubstringIndex_index=12
REM set /a _GetSubstringIndex_index=13
REM set /a _GetSubstringIndex_index=14
REM set /a _GetSubstringIndex_index=15
REM set /a _GetSubstringIndex_index=16
REM set /a _GetSubstringIndex_index=17
REM set /a _GetSubstringIndex_index=18
REM set /a _GetSubstringIndex_index=19
REM set /a _GetSubstringIndex_index=20
REM set /a _GetSubstringIndex_index=21
REM set /a _GetSubstringIndex_index=22
REM set /a _GetSubstringIndex_index=23
REM set /a _GetSubstringIndex_index=24
REM set /a _GetSubstringIndex_index=25
REM set /a _GetSubstringIndex_index=26
REM set /a _GetSubstringIndex_index=27
REM set /a _GetSubstringIndex_index=28
REM set /a _GetSubstringIndex_index=29
REM set /a _GetSubstringIndex_index=30
REM set /a _GetSubstringIndex_index=31
REM set /a _GetSubstringIndex_index=32
REM set /a _GetSubstringIndex_index=33
REM set /a _GetSubstringIndex_index=34
REM set /a _GetSubstringIndex_index=35
REM set /a _GetSubstringIndex_index=36

REM set /a _GetSubstringIndex_stop=0
REM set /a _GetSubstringIndex_stop=1
REM set /a _GetSubstringIndex_stop=2
REM set /a _GetSubstringIndex_stop=3
REM set /a _GetSubstringIndex_stop=4
REM set /a _GetSubstringIndex_stop=5
REM set /a _GetSubstringIndex_stop=7
REM set /a _GetSubstringIndex_stop=8
REM set /a _GetSubstringIndex_stop=9
REM set /a _GetSubstringIndex_stop=10
REM set /a _GetSubstringIndex_stop=11
REM set /a _GetSubstringIndex_stop=12
REM set /a _GetSubstringIndex_stop=13
REM set /a _GetSubstringIndex_stop=14
REM set /a _GetSubstringIndex_stop=15
REM set /a _GetSubstringIndex_stop=16
REM set /a _GetSubstringIndex_stop=17
REM set /a _GetSubstringIndex_stop=18
REM set /a _GetSubstringIndex_stop=19
REM set /a _GetSubstringIndex_stop=20
REM set /a _GetSubstringIndex_stop=21
REM set /a _GetSubstringIndex_stop=22
REM set /a _GetSubstringIndex_stop=23
REM set /a _GetSubstringIndex_stop=24
REM set /a _GetSubstringIndex_stop=25
REM set /a _GetSubstringIndex_stop=26
REM set /a _GetSubstringIndex_stop=27
REM set /a _GetSubstringIndex_stop=28
REM set /a _GetSubstringIndex_stop=29
REM set /a _GetSubstringIndex_stop=30
REM set /a _GetSubstringIndex_stop=31
REM set /a _GetSubstringIndex_stop=32
set /a _GetSubstringIndex_stop=33

:GetSubstringIndex-demo-loop

if %_GetSubstringIndex_index% EQU 0 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 0 set _GetSubstringIndex_testvar=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
if %_GetSubstringIndex_index% EQU 0 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 0 ( echo.&echo %_GetSubstringIndex_index% All FFF string, 100 long, "%_GetSubstringIndex_testpattern%" is the search pattern, Test string is "%_GetSubstringIndex_testvar%")
if %_GetSubstringIndex_index% EQU 0 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 1 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 1 Call :CreateRandomStringPS %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 1 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 1 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 1 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 2 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 2 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 2 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 2 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 2 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 3 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 3 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 3 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 3 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 3 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 4 ( set /a _GetSubstringIndex_index_lenght=1000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 4 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 4 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 4 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 4 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 5 ( set /a _GetSubstringIndex_index_lenght=4000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 5 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 5 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 5 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 5 GoTo :GetSubstringIndex-demo-start-loop


if %_GetSubstringIndex_index% EQU 6 ( set /a _GetSubstringIndex_index_lenght=8000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 6 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 6 set _GetSubstringIndex_testpattern=TEST
if %_GetSubstringIndex_index% EQU 6 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern,)
if %_GetSubstringIndex_index% EQU 6 echo Test string is ::"%_GetSubstringIndex_testvar:~,8000%"{TRUNKATED AT 8000}::
if %_GetSubstringIndex_index% EQU 6 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 7 echo  Repeat tests 1-6, but with auto generated alpha numeric testpattern of size variable between 10 and 20
set /a _GetSubstringIndex_testpattern_min=10 & set /a _GetSubstringIndex_testpattern_max=20 & set "_GetSubstringIndex_testpattern_settings="
set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100

if %_GetSubstringIndex_index% EQU 7 set _GetSubstringIndex_testvar=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
if %_GetSubstringIndex_index% EQU 7 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 7 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 7 ( echo.&echo %_GetSubstringIndex_index% All FFF string, 100 long, "%_GetSubstringIndex_testpattern%" is the search pattern, Test string is "%_GetSubstringIndex_testvar%")
if %_GetSubstringIndex_index% EQU 7 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 8 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 8 Call :CreateRandomStringPS %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 8 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 8 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 8 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 8 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 9 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 9 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 9 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 9 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 9 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 9 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 10 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 10 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 10 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 10 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 10 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 10 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 11 ( set /a _GetSubstringIndex_index_lenght=1000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 11 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 11 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 11 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 11 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 11 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 12 ( set /a _GetSubstringIndex_index_lenght=4000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 12 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 12 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 12 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 12 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 12 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 13 ( set /a _GetSubstringIndex_index_lenght=8000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 13 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 13 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 13 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 13 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern,)
if %_GetSubstringIndex_index% EQU 13 echo Test string is ::"%_GetSubstringIndex_testvar:~,8000%"{TRUNKATED AT 8000}::
if %_GetSubstringIndex_index% EQU 13 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 14 echo  Repeat tests 7-13, but with punctuation and space but no poison in the test pattern
set /a _GetSubstringIndex_testpattern_min=10 & set /a _GetSubstringIndex_testpattern_max=20 & set "_GetSubstringIndex_testpattern_settings=PUNCTUATION NOPOISON SPACE"

if %_GetSubstringIndex_index% EQU 14 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 14 set _GetSubstringIndex_testvar=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
if %_GetSubstringIndex_index% EQU 14 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 14 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 14 ( echo.&echo %_GetSubstringIndex_index% All FFF string, 100 long, "%_GetSubstringIndex_testpattern%" is the search pattern, Test string is "%_GetSubstringIndex_testvar%")
if %_GetSubstringIndex_index% EQU 14 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 15 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 15 Call :CreateRandomStringPS %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 15 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 15 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 15 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 15 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 16 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 16 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 16 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 16 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 16 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 16 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 17 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 17 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 17 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 17 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 17 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 17 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 18 ( set /a _GetSubstringIndex_index_lenght=1000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 18 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 18 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 18 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 18 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 18 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 19 ( set /a _GetSubstringIndex_index_lenght=4000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 19 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 19 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 19 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 19 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 19 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 20 ( set /a _GetSubstringIndex_index_lenght=8000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 20 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 20 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 20 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 20 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, )
if %_GetSubstringIndex_index% EQU 20 echo Test string is ::"%_GetSubstringIndex_testvar:~,8000%"{TRUNKATED AT 8000}::
if %_GetSubstringIndex_index% EQU 20 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 21 echo  Repeat tests 14-20, but including poison in the test pattern 
set /a _GetSubstringIndex_testpattern_min=10 & set /a _GetSubstringIndex_testpattern_max=20 & set "_GetSubstringIndex_testpattern_settings=PUNCTUATION SPACE"

if %_GetSubstringIndex_index% EQU 21 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 21 set _GetSubstringIndex_testvar=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
if %_GetSubstringIndex_index% EQU 21 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 21 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 21 ( echo.&echo %_GetSubstringIndex_index% All FFF string, 100 long, "%_GetSubstringIndex_testpattern%" is the search pattern, Test string is "%_GetSubstringIndex_testvar%")
if %_GetSubstringIndex_index% EQU 21 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 22 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 22 Call :CreateRandomStringPS %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 22 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 22 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 22 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 22 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 23 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 23 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 23 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 23 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 23 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 23 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 24 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 24 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 24 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 24 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 24 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 24 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 25 ( set /a _GetSubstringIndex_index_lenght=1000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 25 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 25 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 25 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 25 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 25 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 25 ( set /a _GetSubstringIndex_index_lenght=4000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 25 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 25 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 25 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 25 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 25 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 26 ( set /a _GetSubstringIndex_index_lenght=8000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 26 Call :CreateRandomStringPS PUNCTUATION NOPOISON SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 26 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 26 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 26 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, )
if %_GetSubstringIndex_index% EQU 26 echo Test string is ::"%_GetSubstringIndex_testvar:~,8000%"{TRUNKATED AT 8000}::
if %_GetSubstringIndex_index% EQU 26 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 27 echo  Repeat tests 21-26, but with poison characters in the test string too
set /a _GetSubstringIndex_testpattern_min=10 & set /a _GetSubstringIndex_testpattern_max=20 & set "_GetSubstringIndex_testpattern_settings=PUNCTUATION NOPOISON SPACE"

if %_GetSubstringIndex_index% EQU 27 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 27 set "_GetSubstringIndex_testvar=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)(%^&=<>|FFFF"FFFFFFFFF"
if %_GetSubstringIndex_index% EQU 27 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 27 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 27 ( echo.&echo %_GetSubstringIndex_index% All FFF string, 100 long, "%_GetSubstringIndex_testpattern%" is the search pattern, Test string is "%_GetSubstringIndex_testvar%")
if %_GetSubstringIndex_index% EQU 27 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 28 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 28 Call :CreateRandomStringPS PUNCTUATION %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 28 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 28 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 28 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 28 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 29 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 29 Call :CreateRandomStringPS PUNCTUATION SPACE %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 29 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 29 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 29 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 29 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 30 ( set /a _GetSubstringIndex_index_lenght=100 & set /a _GetSubstringIndex_index_count=100 )
if %_GetSubstringIndex_index% EQU 30 Call :CreateRandomStringPS PUNCTUATION SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 30 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 30 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 30 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 30 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 31 ( set /a _GetSubstringIndex_index_lenght=1000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 31 Call :CreateRandomStringPS PUNCTUATION SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 31 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 31 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 31 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 31 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 32 ( set /a _GetSubstringIndex_index_lenght=4000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 32 Call :CreateRandomStringPS PUNCTUATION SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 32 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 32 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 32 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, Test string is ::"%_GetSubstringIndex_testvar%"::)
if %_GetSubstringIndex_index% EQU 32 GoTo :GetSubstringIndex-demo-start-loop

if %_GetSubstringIndex_index% EQU 33 ( set /a _GetSubstringIndex_index_lenght=8000 & set /a _GetSubstringIndex_index_count=50 )
if %_GetSubstringIndex_index% EQU 33 Call :CreateRandomStringPS PUNCTUATION SPACE EXTENDED %_GetSubstringIndex_index_lenght% _GetSubstringIndex_testvar
if %_GetSubstringIndex_index% EQU 33 call :rnd _GetSubstringIndex_testpattern %_GetSubstringIndex_testpattern_min% %_GetSubstringIndex_testpattern_max%
if %_GetSubstringIndex_index% EQU 33 Call :CreateRandomStringPS %_GetSubstringIndex_testpattern_settings% %_GetSubstringIndex_testpattern% _GetSubstringIndex_testpattern
if %_GetSubstringIndex_index% EQU 33 ( echo.&echo %_GetSubstringIndex_index% Alphanumeric random string, with punctuation and space and nopoison %_GetSubstringIndex_index_lenght% long, %_GetSubstringIndex_index_count% count ::"%_GetSubstringIndex_testpattern%":: is the search pattern, )
if %_GetSubstringIndex_index% EQU 33 echo Test string is ::"%_GetSubstringIndex_testvar:~,8000%"{TRUNKATED AT 8000}::
if %_GetSubstringIndex_index% EQU 33 GoTo :GetSubstringIndex-demo-start-loop

:GetSubstringIndex-demo-start-loop
echo test
set /a _GetSubstringIndex_index_index=0
Call :ClearVariablesByPrefix _GetSubstringIndex_testarray 
echo.&echo Starting test %_GetSubstringIndex_index%, string lenght %_GetSubstringIndex_index_lenght%, loop  count %_GetSubstringIndex_index_count%&echo.
:GetSubstringIndex-demo-run-loop
Call :ReplaceString "%_GetSubstringIndex_testvar%" "%_GetSubstringIndex_testpattern%" _GetSubstringIndex_testarray[%_GetSubstringIndex_index_index%] %_GetSubstringIndex_index_index% ""
set /a _GetSubstringIndex_index_index+=1
if %_GetSubstringIndex_index_index% LEQ %_GetSubstringIndex_index_count% GoTo :GetSubstringIndex-demo-run-loop
echo.&echo _GetSubstringIndex_testarray[] values inserted with test pattern ::"%_GetSubstringIndex_testpattern%":: & set /a _GetSubstringIndex_index_index=0
echo.&echo GetSubstringIndex is called byref&echo.
:GetSubstringIndex-demo-run-loop-loop
Call :GetSubstringIndex "_GetSubstringIndex_testarray[%_GetSubstringIndex_index_index%]" "%_GetSubstringIndex_testpattern%" "" 
if defined _GetSubstringIndex_show_string call echo Index %_GetSubstringIndex_index_index% : result %errorlevel%  ::"%%_GetSubstringIndex_testarray[%_GetSubstringIndex_index_index%]:~,8000%%"::
if not defined _GetSubstringIndex_show_string call echo Index %_GetSubstringIndex_index_index% : result %errorlevel% 
set /a _GetSubstringIndex_index_index+=1
if %_GetSubstringIndex_index_index% LEQ %_GetSubstringIndex_index_count% GoTo :GetSubstringIndex-demo-run-loop-loop
echo.&echo GetSubstringIndex is called byval&echo.& set /a _GetSubstringIndex_index_index=0
:GetSubstringIndex-demo-run-loop-loop-loop
Call :GetSubstringIndex "%%_GetSubstringIndex_testarray[%_GetSubstringIndex_index_index%]%%" "%_GetSubstringIndex_testpattern%" "" 
if defined _GetSubstringIndex_show_string call echo Index %_GetSubstringIndex_index_index% : result %errorlevel%  ::"%%_GetSubstringIndex_testarray[%_GetSubstringIndex_index_index%]:~,8000%%"::
if not defined _GetSubstringIndex_show_string call echo Index %_GetSubstringIndex_index_index% : result %errorlevel%
set /a _GetSubstringIndex_index_index+=1
if %_GetSubstringIndex_index_index% LEQ %_GetSubstringIndex_index_count% GoTo :GetSubstringIndex-demo-run-loop-loop-loop
set /a _GetSubstringIndex_index+=1
if %_GetSubstringIndex_index% LSS %_GetSubstringIndex_stop% GoTo :GetSubstringIndex-demo-loop

Call :ClearVariablesByPrefix _GetSubstringIndex
GoTo :EOF

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#4 Post by shodan » 22 May 2024 01:22

I am working on a split function

It currently works, here is the output

Code: Select all

GetSubstringIndex-DEMO.bat
delimiter :,: input string :THIS,IS,A,TEST: comment : classic comma separated, works
0:THIS 1:IS 2:A 3:TEST
delimiter :.: input string :THIS.IS.A.TEST: comment : using dots instead, works
0:THIS 1:IS 2:A 3:TEST
delimiter :Z: input string :THISZISZAZTEST: comment : using a letter, Z, works
0:THIS 1:IS 2:A 3:TEST
delimiter :::: input string :THIS::IS::A::TEST: comment : using two character delimiter, double punctuation, works
0:THIS 1:IS 2:A 3:TEST
delimiter :123: input string :THIS123IS123A123TEST: comment : using three characters, numbers, works
0:THIS 1:IS 2:A 3:TEST
delimiter :[COLUMN]: input string :THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST: comment : using delimiter inside square brackets, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^^: input string :THIS^^IS^^A^^TEST: comment : poison character, carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^^^^: input string :THIS^^^^IS^^^^A^^^^TEST: comment : poison character, double carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST

Now using byref instead of byval

delimiter :,: input string :THIS,IS,A,TEST: comment classic comma separated, works
0:THIS 1:IS 2:A 3:TEST
delimiter :.: input string :THIS.IS.A.TEST: comment using dots instead, works
0:THIS 1:IS 2:A 3:TEST
delimiter :Z: input string :THISZISZAZTEST: comment using a letter, Z, works
0:THIS 1:IS 2:A 3:TEST
delimiter :::: input string :THIS::IS::A::TEST: comment using two character delimiter, double punctuation, works
0:THIS 1:IS 2:A 3:TEST
delimiter :123: input string :THIS123IS123A123TEST: comment using three characters, numbers, works
0:THIS 1:IS 2:A 3:TEST
delimiter :[COLUMN]: input string :THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST: comment using delimiter inside square brackets, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^: input string :THIS^IS^A^TEST: comment poison character, carret, they get further doubled, works
0:THIS^IS^A^TEST
delimiter :^^: input string :THIS^^IS^^A^^TEST: comment poison character, double carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST
delimiter :&: input string :THIS&IS&A&TEST: comment poison character, ampersands, doesn't break but does not split either
0:THIS&IS&A&TEST
delimiter :%: input string :THIS%IS%A%TEST: comment percent signs, works
0:THIS 1:IS 2:A 3:TEST
delimiter :!: input string :THIS!IS!A!TEST: comment poison character, exclamation mark, doesn't break test but does not split
0:THISATEST
Here is the test function

Code: Select all

:split-demo
call :split-demo-helper "THIS,IS,A,TEST" "," _split_demo_array "classic comma separated, works"
call :split-demo-helper "THIS.IS.A.TEST" "." _split_demo_array "using dots instead, works"
call :split-demo-helper "THISZISZAZTEST" "Z" _split_demo_array "using a letter, Z, works"
call :split-demo-helper "THIS::IS::A::TEST" "::" _split_demo_array "using two character delimiter, double punctuation, works"
call :split-demo-helper "THIS123IS123A123TEST" "123" _split_demo_array "using three characters, numbers, works" 
call :split-demo-helper "THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST" "[COLUMN]" _split_demo_array "using delimiter inside square brackets, works"
call :split-demo-helper "THIS^IS^A^TEST" "^" _split_demo_array "poison character, carret, they get further doubled, works"
call :split-demo-helper "THIS^^IS^^A^^TEST" "^^" _split_demo_array "poison character, double carret, they get further doubled, works"
REM call :split-demo-helper "THIS%%IS%%A%%TEST" "%%" _split_demo_array "percent signs this breaks the test"
REM call :split-demo-helper "THIS|IS|A|TEST" "|" _split_demo_array  "poison character, pipe, this breaks the test"
REM call :split-demo-helper "THIS!IS!A!TEST" "!" _split_demo_array  "poison character, exclamation mark, this breaks the test"
REM call :split-demo-helper "THIS&IS&A&TEST" "&" _split_demo_array "poison character, ampersands, this breaks the test"

echo.
echo Now using byref instead of byval
echo.

set "_split_demo_test=THIS,IS,A,TEST" & set "_split_demo_delim=," & set "_split_demo_comment=classic comma separated, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"
set "_split_demo_test=THIS.IS.A.TEST" & set "_split_demo_delim=." & set "_split_demo_comment=using dots instead, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THISZISZAZTEST" & set "_split_demo_delim=Z" & set "_split_demo_comment=using a letter, Z, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THIS::IS::A::TEST" & set "_split_demo_delim=::" & set "_split_demo_comment=using two character delimiter, double punctuation, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THIS123IS123A123TEST" & set "_split_demo_delim=123" & set "_split_demo_comment=using three characters, numbers, works" 
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST" & set "_split_demo_delim=[COLUMN]" & set "_split_demo_comment=using delimiter inside square brackets, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THIS^IS^A^TEST" & set "_split_demo_delim=^" & set "_split_demo_comment=poison character, carret, they get further doubled, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array  "%_split_demo_comment%"
set "_split_demo_test=THIS^^IS^^A^^TEST" & set "_split_demo_delim=^^" & set "_split_demo_comment=poison character, double carret, they get further doubled, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"
set "_split_demo_test=THIS&IS&A&TEST" & set "_split_demo_delim=&" & set "_split_demo_comment=poison character, ampersands, doesn't break but does not split either"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"
set "_split_demo_test=THIS%%IS%%A%%TEST" & set "_split_demo_delim=%%" & set "_split_demo_comment=percent signs, works"
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"
set "_split_demo_test=THIS|IS|A|TEST" & set "_split_demo_delim=|" & set "_split_demo_comment=poison character, pipe, this breaks the test"
REM call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"
set "_split_demo_test=THIS^!IS^!A^!TEST" & set "_split_demo_delim=^!" & set "_split_demo_comment=poison character, exclamation mark, doesn't break test but does not split
call :split-demo-2-helper _split_demo_test _split_demo_delim _split_demo_array "%_split_demo_comment%"


Call :ClearVariablesByPrefix _split_demo

GoTo :EOF

Here is the split function

I left in the comments regarding upcoming improvements, you can ignore them if testing

Code: Select all

::Usage Call :split InputString Delimiter OutputArray optional limit [CASESENSITIVE]
:Split
set "_Split_prefix=_SPLT"
set "_SPLT_CaseSensitivity=/i"
set "_SPLT_Input=%~1"
set "_SPLT_Delimiter=%~2"
set "_SPLT_Output=%~3"
shift & shift & shift
echo.%~1| findstr /r "[^0123456789]" >nul && ( set /a _SPLT_Limit=%~1 & shift )
if "[%~1]" EQU "[CASESENSITIVE]" set "_SPLT_CaseSensitivity="
setlocal enabledelayedexpansion
set "_SPLT_localscope=true"
set "_SPLT_Input_Pointer=_SPLT_Input" 
set "_SPLT_Delimiter_Pointer=_SPLT_Delimiter"
if defined !_SPLT_Input! ( set "_SPLT_Input_Pointer=!_SPLT_Input!" )
if defined !_SPLT_Delimiter! ( set "_SPLT_Delimiter_Pointer=!_SPLT_Delimiter!" )
REM if defined !_SPLT_Delimiter!.ubound set /a _SPLT_Delimiter_ubound=!%_SPLT_Delimiter%.ubound!
REM if defined !_SPLT_Delimiter!.ubound set "_SPLT_Delimiter_Pointer=!_SPLT_Delimiter![!%_SPLT_Delimiter%.lbound!]"
if defined %_SPLT_Output%.ubound set /a _SPLT_Output_ubound=!%_SPLT_Output%.ubound!
if not defined _SPLT_Output_ubound set /a _SPLT_Output_ubound=-1
Call :len "%_SPLT_Input_Pointer%" _SPLT_Input_len
Call :len "%_SPLT_Delimiter_Pointer%" _SPLT_Delimiter_len
REM if not defined !_SPLT_Delimiter!.ubound GoTo :Split-get-delimiter-len-skip
REM :Split-get-delimiter-len-loop
REM FOR EACH DELIMITER, FIND DELIMITER.LEN
REM :Split-get-delimiter-len-skip
REM if defined _SPLT_Delimiter_ubound set /a _SPLT_Delimiter_index=0
set /a _SPLT_Index=0


:Split-loop
REM :Split-delimiter-loop ?
Call :GetSubstringIndex "%_SPLT_Input_Pointer%" "%_SPLT_Delimiter_Pointer%" %_SPLT_Index% _SPLT_end

REM --------------------- substring replacement ----------------------
REM set _GSSI_Input="%_SPLT_Input_Pointer%"
REM set _GSSI_Search="%_SPLT_Delimiter_Pointer%"
REM set /a _GSSI_StartIndex=%_SPLT_Index% 2>nul
REM set "_GSSI_Output=_SPLT_end
REM _GSSI_min_search
REM _SPLT_Input_len
REM _SPLT_Delimiter_len
REM --------------------- substring replacement ----------------------

REM --------------------- substring replacement ----------------------

REM Set search window len = 64
REM Search window for search term
REM if not found, move start index to end of current window, double window lenght, search again
REM if window len greater than input len and still not found, return only the current element
REM when search them is first found
REM search first half of this window, if found, half again and so on until reach "min search window len"
REM if not found in first half, search second half, if found, move startindex, half this part and so on until reach "min search window len"

if %_SPLT_end% EQU -1 ( set /a _SPLT_count=%_SPLT_Input_len%-%_SPLT_Index% & set /a _SPLT_end=%_SPLT_Input_len% ) else ( set /a _SPLT_count=%_SPLT_end%-%_SPLT_Index% )
set /a _SPLT_Output_ubound+=1
set "%_SPLT_Output%[%_SPLT_Output_ubound%]=!%_SPLT_Input_Pointer%:~%_SPLT_Index%,%_SPLT_count%!"
REM if %_SPLT_Delimiter_index% LEQ %_SPLT_Delimiter_ubound% GoTo :Split-delimiter-loop
set /a _SPLT_Index=%_SPLT_end%+%_SPLT_Delimiter_len%
if %_SPLT_end% NEQ %_SPLT_Input_len% GoTo :Split-loop
set /a %_SPLT_Output%.ubound=%_SPLT_Output_ubound%
for /F "delims=" %%a in ('set %_SPLT_Output%') do (
	endlocal
	set "%%a"
	)
Call :ClearVariablesByPrefix %_Split_prefix% _Split_prefix  & exit /b %_SPLT_count%
REM thanks to https://stackoverflow.com/questions/49041934/how-to-return-an-array-of-values-across-endlocal https://stackoverflow.com/a/49042678

Here is the current version of GetSubstringIndex, I have found two improvements that are promising, I will also add multiple delimiters support

Code: Select all

::Usage Call :GetSubstringIndex InputString SearchString StartIndex Optional OutputIndexVar ... InputStringN SearchStringN StartIndexN Optional OutputIndexVar
:GetSubstringIndex
set "_GetSubstringIndex_prefix=_GSSI"
set _GSSI_Input=%~1
set _GSSI_Search=%~2
set /a _GSSI_StartIndex=%~3 2>nul
set "_GSSI_Output=%~4"
if not defined _GSSI_StartIndex set /a _GSSI_StartIndex=0
setlocal enabledelayedexpansion
if defined %_GSSI_Search% set _GSSI_Search=!%_GSSI_Search%!
set "_GSSI_Input_Pointer=_GSSI_Input"
if defined !_GSSI_Input! (
 set "_GSSI_Input_Pointer=%_GSSI_Input%" 
 )
Call :len "%_GSSI_Input_Pointer%" _GSSI_Input_len
if defined "%_GSSI_Search%" Call :len "%_GSSI_Search%" _GSSI_Search_len
if not defined "%_GSSI_Search%" Call :len _GSSI_Search _GSSI_Search_len
set /a _GSSI_Input_len-=1
set /a _GSSI_min_search=(%_GSSI_Search_len%*2)

REM Start checking from 0 to 5 (times _GSSI_Search_len)
REM then double search len until found, or end of string reached
REM on each doubling, more startindex to end of region known not to contain search term
REM on first found
REM check first half, if not found second half
REM next check half of found then second half of found 
REM until you reach min search len then go to stage 3

:GetSubstringIndex-loop

REM start searching 64 char of input len, go up if not found, doubling until the rest of the input is searched 
REM probably use findstr instead of string substitution for finding match, at least in stage 1
REM once match is found, narrow down by splitting search in half

set /a _GSSI_HalfInputLen=%_GSSI_Search_len%+(%_GSSI_Input_len%/2)
if %_GSSI_HalfInputLen% LEQ %_GSSI_min_search% ( 
	set /a _GSSI_max_search=%_GSSI_StartIndex%+%_GSSI_min_search%+1 & GoTo :GetSubstringIndex-loop2 
	)
set /a _GSSI_Middle=%_GSSI_StartIndex%+%_GSSI_HalfInputLen%
set /a _GSSI_HalfInputLenPLUSSearchLenMINUSOne=%_GSSI_HalfInputLen%+%_GSSI_Search_len%-1
set _GSSI_FirstHalf=!%_GSSI_Input_Pointer%:~%_GSSI_StartIndex%,%_GSSI_HalfInputLenPLUSSearchLenMINUSOne%!
set _GSSI_SecondHalf=!%_GSSI_Input_Pointer%:~%_GSSI_Middle%,%_GSSI_HalfInputLen%!
set _GSSI_FirstResult=!_GSSI_FirstHalf:%_GSSI_Search%=!
set _GSSI_SecondResult=!_GSSI_SecondHalf:%_GSSI_Search%=!
if !_GSSI_FirstHalf! NEQ !_GSSI_FirstResult! ( set /a _GSSI_Input_len=%_GSSI_HalfInputLen% & GoTo :GetSubstringIndex-loop )
if !_GSSI_SecondHalf! NEQ !_GSSI_SecondResult! ( set /a _GSSI_StartIndex=%_GSSI_Middle% & GoTo :GetSubstringIndex-loop )
set /a _GSSI_StartIndex=-1 & GoTo :GetSubstringIndex-end
:GetSubstringIndex-loop2
set _GSSI_FinalSearch=!%_GSSI_Input_Pointer%:~%_GSSI_StartIndex%,%_GSSI_Search_len%!
if !_GSSI_FinalSearch! EQU !_GSSI_Search! GoTo :GetSubstringIndex-end
set /a _GSSI_StartIndex+=1
if %_GSSI_StartIndex% LEQ %_GSSI_max_search% GoTo :GetSubstringIndex-loop2
set /a _GSSI_StartIndex=-1 & GoTo :GetSubstringIndex-end
:GetSubstringIndex-end
if "[%~7]" NEQ "[]" ( shift & shift & shift & shift & shift & GoTo :GetSubstringIndex )
endlocal & set _GSSI_StartIndex=%_GSSI_StartIndex% & if defined _GSSI_Output set /a %_GSSI_Output%=%_GSSI_StartIndex%
Call :ClearVariablesByPrefix %_GetSubstringIndex_prefix% _GetSubstringIndex_prefix & exit /b %_GSSI_StartIndex% 

And here is my current test file
GetSubstringIndex-DEMO.zip
(8.84 KiB) Downloaded 1033 times

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#5 Post by shodan » 22 May 2024 03:00

Just did a better :split

Still has bugs but that one should be a lot faster on long input strings

It should respect CASESENSITIVE

Limit does nothing

still breaks on byval percentsigns, byval pipe byref pipe byval exclamationmark
still fails to split on byval ampersand byref single carret, byref ampersand, byref exclamationmark

still does not work with multiple delimiter ( array of delimiters on the input)

TESTED WITH A 8040 input string !!! OMG OMG IT WORKS !!!!!

Code: Select all

::Usage Call :split InputString Delimiter OutputArray optional limit [CASESENSITIVE]
:Split
set "_Split_prefix=_SPLT"
set "_SPLT_CaseSensitivity=/i"
set "_SPLT_Input=%~1"
set "_SPLT_Delimiter=%~2"
set "_SPLT_Output=%~3"
shift & shift & shift
echo.%~1| findstr /r "[^0123456789]" >nul && ( set /a _SPLT_Limit=%~1 & shift )
if "[%~1]" EQU "[CASESENSITIVE]" set "_SPLT_CaseSensitivity="
setlocal enabledelayedexpansion
set "_SPLT_localscope=true"
set "_SPLT_Input_Pointer=_SPLT_Input" 
set "_SPLT_Delimiter_Pointer=_SPLT_Delimiter"
if defined !_SPLT_Input! ( set "_SPLT_Input_Pointer=!_SPLT_Input!" )
if defined !_SPLT_Delimiter! ( set "_SPLT_Delimiter_Pointer=!_SPLT_Delimiter!" )
if defined %_SPLT_Output%.ubound set /a _SPLT_Output_ubound=!%_SPLT_Output%.ubound!
if not defined _SPLT_Output_ubound set /a _SPLT_Output_ubound=-1
Call :len "%_SPLT_Input_Pointer%" _SPLT_Input_len
Call :len "%_SPLT_Delimiter_Pointer%" _SPLT_Delimiter_len
set /a _SPLT_Index=0
:Split-loop
set _SPLT_Search=!%_SPLT_Delimiter_Pointer%!
if %_SPLT_Input_len% LSS 64 ( set /a _SPLT_Search_Window_len=%_SPLT_Input_len% ) else ( set /a _SPLT_Search_Window_len=64 )
set /a _SPLT_end=%_SPLT_Index%
set /a _SPLT_min_search=%_SPLT_Delimiter_len%*2
:Split-substring-pre-loop
set _SPLT_CurrentWindow=!%_SPLT_Input_Pointer%:~%_SPLT_end%,%_SPLT_Search_Window_len%!
set _SPLT_CurrentWindowResult=!_SPLT_FirstHalf:%_SPLT_Search%=!
if %_SPLT_CaseSensitivity% !_SPLT_CurrentWindow! EQU !_SPLT_CurrentWindowResult! ( if %_SPLT_Search_Window_len% LSS %_SPLT_Input_len% ( set /a _SPLT_end=-1 & GoTo :Split-substring-end ) else ( set /a _SPLT_end=%_SPLT_end%+%_SPLT_Search_Window_len%-1 & set /a _SPLT_Search_Window_len=%_SPLT_Search_Window_len%*2 & GoTo :Split-substring-pre-loop ) )
:Split-substring-loop
set /a _SPLT_HalfInputLen=%_SPLT_Delimiter_len%+(%_SPLT_Search_Window_len%/2)
if %_SPLT_HalfInputLen% LEQ %_SPLT_min_search% ( 
	set /a _SPLT_max_search=%_SPLT_end%+%_SPLT_min_search%+1 & GoTo :Split-substring-loop2 
	)
set /a _SPLT_Middle=%_SPLT_end%+%_SPLT_HalfInputLen%
set /a _SPLT_HalfInputLenPLUSSearchLenMINUSOne=%_SPLT_HalfInputLen%+%_SPLT_Delimiter_len%-1
set _SPLT_FirstHalf=!%_SPLT_Input_Pointer%:~%_SPLT_end%,%_SPLT_HalfInputLenPLUSSearchLenMINUSOne%!
set _SPLT_SecondHalf=!%_SPLT_Input_Pointer%:~%_SPLT_Middle%,%_SPLT_HalfInputLen%!
set _SPLT_FirstResult=!_SPLT_FirstHalf:%_SPLT_Search%=!
set _SPLT_SecondResult=!_SPLT_SecondHalf:%_SPLT_Search%=!
if %_SPLT_CaseSensitivity% !_SPLT_FirstHalf! NEQ !_SPLT_FirstResult! ( set /a _SPLT_Search_Window_len=%_SPLT_HalfInputLen% & GoTo :Split-substring-loop )
if %_SPLT_CaseSensitivity% !_SPLT_SecondHalf! NEQ !_SPLT_SecondResult! ( set /a _SPLT_end=%_SPLT_Middle% & GoTo :Split-substring-loop )
set /a _SPLT_end=-1 & GoTo :Split-substring-end
:Split-substring-loop2
set _SPLT_FinalSearch=!%_SPLT_Input_Pointer%:~%_SPLT_end%,%_SPLT_Delimiter_len%!
if !_SPLT_FinalSearch! EQU !_SPLT_Search! GoTo :Split-substring-end
set /a _SPLT_end+=1
if %_SPLT_end% LEQ %_SPLT_max_search% GoTo :Split-substring-loop2
set /a _SPLT_end=-1 & GoTo :Split-substring-end
:Split-substring-end
if %_SPLT_end% EQU -1 ( set /a _SPLT_count=%_SPLT_Input_len%-%_SPLT_Index% & set /a _SPLT_end=%_SPLT_Input_len% ) else ( set /a _SPLT_count=%_SPLT_end%-%_SPLT_Index% )
set /a _SPLT_Output_ubound+=1
set "%_SPLT_Output%[%_SPLT_Output_ubound%]=!%_SPLT_Input_Pointer%:~%_SPLT_Index%,%_SPLT_count%!"
set /a _SPLT_Index=%_SPLT_end%+%_SPLT_Delimiter_len%
if %_SPLT_end% NEQ %_SPLT_Input_len% GoTo :Split-loop
set /a %_SPLT_Output%.ubound=%_SPLT_Output_ubound%
for /F "delims=" %%a in ('set %_SPLT_Output%') do (
	endlocal
	set "%%a"
	)
Call :ClearVariablesByPrefix %_Split_prefix% _Split_prefix  & exit /b %_SPLT_count%

Here is the latest test outputs

Code: Select all

delimiter :,: input string :THIS,IS,A,TEST: comment : classic comma separated, works
0:THIS 1:IS 2:A 3:TEST
delimiter :.: input string :THIS.IS.A.TEST: comment : using dots instead, works
0:THIS 1:IS 2:A 3:TEST
delimiter :Z: input string :THISZISZAZTEST: comment : using a letter, Z, works
0:THIS 1:IS 2:A 3:TEST
delimiter :::: input string :THIS::IS::A::TEST: comment : using two character delimiter, double punctuation, works
0:THIS 1:IS 2:A 3:TEST
delimiter :123: input string :THIS123IS123A123TEST: comment : using three characters, numbers, works
0:THIS 1:IS 2:A 3:TEST
delimiter :[COLUMN]: input string :THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST: comment : using delimiter inside square brackets, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^^: input string :THIS^^IS^^A^^TEST: comment : poison character, carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^^^^: input string :THIS^^^^IS^^^^A^^^^TEST: comment : poison character, double carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST
delimiter :&: input string :THIS&IS&A&TEST: comment : poison character, ampersands, doesn't break test but does not split
0:THIS&IS&A&TEST

Now using byref instead of byval

delimiter :,: input string :THIS,IS,A,TEST: comment classic comma separated, works
0:THIS 1:IS 2:A 3:TEST
delimiter :.: input string :THIS.IS.A.TEST: comment using dots instead, works
0:THIS 1:IS 2:A 3:TEST
delimiter :Z: input string :THISZISZAZTEST: comment using a letter, Z, works
0:THIS 1:IS 2:A 3:TEST
delimiter :::: input string :THIS::IS::A::TEST: comment using two character delimiter, double punctuation, works
0:THIS 1:IS 2:A 3:TEST
delimiter :123: input string :THIS123IS123A123TEST: comment using three characters, numbers, works
0:THIS 1:IS 2:A 3:TEST
delimiter :[COLUMN]: input string :THIS[COLUMN]IS[COLUMN]A[COLUMN]TEST: comment using delimiter inside square brackets, works
0:THIS 1:IS 2:A 3:TEST
delimiter :^: input string :THIS^IS^A^TEST: comment poison character, carret, they get further doubled, doesn't break test but does not split
0:THIS^IS^A^TEST
delimiter :^^: input string :THIS^^IS^^A^^TEST: comment poison character, double carret, they get further doubled, works
0:THIS 1:IS 2:A 3:TEST
delimiter :&: input string :THIS&IS&A&TEST: comment poison character, ampersands, doesn't break but does not split either
0:THIS&IS&A&TEST
delimiter :%: input string :THIS%IS%A%TEST: comment percent signs, works
0:THIS 1:IS 2:A 3:TEST
delimiter :!: input string :THIS!IS!A!TEST: comment poison character, exclamation mark, doesn't break test but does not split
0:THISATEST

more tests

delimiter :,: input string :,: comment : 1 char string that contains only the delimiter, should return two empty array element
0: 1:
delimiter :,: input string :.: comment : 1 char string that doesn't contains only the delimiter, should return one array element with input
0:.
delimiter :,: input string :1234567890: comment : 10 char string that doesn't contains only the delimiter, should return one array element with input
0:1234567890

test with long input strings

delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 1006 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890
delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 2014 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890 84:1234567890 85:1234567890 86:1234567890 87:1234567890 88:1234567890 89:1234567890 90:1234567890 91:1234567890 92:1234567890 93:1234567890 94:1234567890 95:1234567890 96:1234567890 97:1234567890 98:1234567890 99:1234567890 100:1234567890 101:1234567890 102:1234567890 103:1234567890 104:1234567890 105:1234567890 106:1234567890 107:1234567890 108:1234567890 109:1234567890 110:1234567890 111:1234567890 112:1234567890 113:1234567890 114:1234567890 115:1234567890 116:1234567890 117:1234567890 118:1234567890 119:1234567890 120:1234567890 121:1234567890 122:1234567890 123:1234567890 124:1234567890 125:1234567890 126:1234567890 127:1234567890 128:1234567890 129:1234567890 130:1234567890 131:1234567890 132:1234567890 133:1234567890 134:1234567890 135:1234567890 136:1234567890 137:1234567890 138:1234567890 139:1234567890 140:1234567890 141:1234567890 142:1234567890 143:1234567890 144:1234567890 145:1234567890 146:1234567890 147:1234567890 148:1234567890 149:1234567890 150:1234567890 151:1234567890 152:1234567890 153:1234567890 154:1234567890 155:1234567890 156:1234567890 157:1234567890 158:1234567890 159:1234567890 160:1234567890 161:1234567890 162:1234567890 163:1234567890 164:1234567890 165:1234567890 166:1234567890 167:1234567890
delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 3020 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890 84:1234567890 85:1234567890 86:1234567890 87:1234567890 88:1234567890 89:1234567890 90:1234567890 91:1234567890 92:1234567890 93:1234567890 94:1234567890 95:1234567890 96:1234567890 97:1234567890 98:1234567890 99:1234567890 100:1234567890 101:1234567890 102:1234567890 103:1234567890 104:1234567890 105:1234567890 106:1234567890 107:1234567890 108:1234567890 109:1234567890 110:1234567890 111:1234567890 112:1234567890 113:1234567890 114:1234567890 115:1234567890 116:1234567890 117:1234567890 118:1234567890 119:1234567890 120:1234567890 121:1234567890 122:1234567890 123:1234567890 124:1234567890 125:1234567890 126:1234567890 127:1234567890 128:1234567890 129:1234567890 130:1234567890 131:1234567890 132:1234567890 133:1234567890 134:1234567890 135:1234567890 136:1234567890 137:1234567890 138:1234567890 139:1234567890 140:1234567890 141:1234567890 142:1234567890 143:1234567890 144:1234567890 145:1234567890 146:1234567890 147:1234567890 148:1234567890 149:1234567890 150:1234567890 151:1234567890 152:1234567890 153:1234567890 154:1234567890 155:1234567890 156:1234567890 157:1234567890 158:1234567890 159:1234567890 160:1234567890 161:1234567890 162:1234567890 163:1234567890 164:1234567890 165:1234567890 166:1234567890 167:12345678901234567890 168:1234567890 169:1234567890 170:1234567890 171:1234567890 172:1234567890 173:1234567890 174:1234567890 175:1234567890 176:1234567890 177:1234567890 178:1234567890 179:1234567890 180:1234567890 181:1234567890 182:1234567890 183:1234567890 184:1234567890 185:1234567890 186:1234567890 187:1234567890 188:1234567890 189:1234567890 190:1234567890 191:1234567890 192:1234567890 193:1234567890 194:1234567890 195:1234567890 196:1234567890 197:1234567890 198:1234567890 199:1234567890 200:1234567890 201:1234567890 202:1234567890 203:1234567890 204:1234567890 205:1234567890 206:1234567890 207:1234567890 208:1234567890 209:1234567890 210:1234567890 211:1234567890 212:1234567890 213:1234567890 214:1234567890 215:1234567890 216:1234567890 217:1234567890 218:1234567890 219:1234567890 220:1234567890 221:1234567890 222:1234567890 223:1234567890 224:1234567890 225:1234567890 226:1234567890 227:1234567890 228:1234567890 229:1234567890 230:1234567890 231:1234567890 232:1234567890 233:1234567890 234:1234567890 235:1234567890 236:1234567890 237:1234567890 238:1234567890 239:1234567890 240:1234567890 241:1234567890 242:1234567890 243:1234567890 244:1234567890 245:1234567890 246:1234567890 247:1234567890 248:1234567890 249:1234567890 250:1234567890
delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 4026 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890 84:1234567890 85:1234567890 86:1234567890 87:1234567890 88:1234567890 89:1234567890 90:1234567890 91:1234567890 92:1234567890 93:1234567890 94:1234567890 95:1234567890 96:1234567890 97:1234567890 98:1234567890 99:1234567890 100:1234567890 101:1234567890 102:1234567890 103:1234567890 104:1234567890 105:1234567890 106:1234567890 107:1234567890 108:1234567890 109:1234567890 110:1234567890 111:1234567890 112:1234567890 113:1234567890 114:1234567890 115:1234567890 116:1234567890 117:1234567890 118:1234567890 119:1234567890 120:1234567890 121:1234567890 122:1234567890 123:1234567890 124:1234567890 125:1234567890 126:1234567890 127:1234567890 128:1234567890 129:1234567890 130:1234567890 131:1234567890 132:1234567890 133:1234567890 134:1234567890 135:1234567890 136:1234567890 137:1234567890 138:1234567890 139:1234567890 140:1234567890 141:1234567890 142:1234567890 143:1234567890 144:1234567890 145:1234567890 146:1234567890 147:1234567890 148:1234567890 149:1234567890 150:1234567890 151:1234567890 152:1234567890 153:1234567890 154:1234567890 155:1234567890 156:1234567890 157:1234567890 158:1234567890 159:1234567890 160:1234567890 161:1234567890 162:1234567890 163:1234567890 164:1234567890 165:1234567890 166:1234567890 167:12345678901234567890 168:1234567890 169:1234567890 170:1234567890 171:1234567890 172:1234567890 173:1234567890 174:1234567890 175:1234567890 176:1234567890 177:1234567890 178:1234567890 179:1234567890 180:1234567890 181:1234567890 182:1234567890 183:1234567890 184:1234567890 185:1234567890 186:1234567890 187:1234567890 188:1234567890 189:1234567890 190:1234567890 191:1234567890 192:1234567890 193:1234567890 194:1234567890 195:1234567890 196:1234567890 197:1234567890 198:1234567890 199:1234567890 200:1234567890 201:1234567890 202:1234567890 203:1234567890 204:1234567890 205:1234567890 206:1234567890 207:1234567890 208:1234567890 209:1234567890 210:1234567890 211:1234567890 212:1234567890 213:1234567890 214:1234567890 215:1234567890 216:1234567890 217:1234567890 218:1234567890 219:1234567890 220:1234567890 221:1234567890 222:1234567890 223:1234567890 224:1234567890 225:1234567890 226:1234567890 227:1234567890 228:1234567890 229:1234567890 230:1234567890 231:1234567890 232:1234567890 233:1234567890 234:1234567890 235:1234567890 236:1234567890 237:1234567890 238:1234567890 239:1234567890 240:1234567890 241:1234567890 242:1234567890 243:1234567890 244:1234567890 245:1234567890 246:1234567890 247:1234567890 248:1234567890 249:1234567890 250:12345678901234567890 251:1234567890 252:1234567890 253:1234567890 254:1234567890 255:1234567890 256:1234567890 257:1234567890 258:1234567890 259:1234567890 260:1234567890 261:1234567890 262:1234567890 263:1234567890 264:1234567890 265:1234567890 266:1234567890 267:1234567890 268:1234567890 269:1234567890 270:1234567890 271:1234567890 272:1234567890 273:1234567890 274:1234567890 275:1234567890 276:1234567890 277:1234567890 278:1234567890 279:1234567890 280:1234567890 281:1234567890 282:1234567890 283:1234567890 284:1234567890 285:1234567890 286:1234567890 287:1234567890 288:1234567890 289:1234567890 290:1234567890 291:1234567890 292:1234567890 293:1234567890 294:1234567890 295:1234567890 296:1234567890 297:1234567890 298:1234567890 299:1234567890 300:1234567890 301:1234567890 302:1234567890 303:1234567890 304:1234567890 305:1234567890 306:1234567890 307:1234567890 308:1234567890 309:1234567890 310:1234567890 311:1234567890 312:1234567890 313:1234567890 314:1234567890 315:1234567890 316:1234567890 317:1234567890 318:1234567890 319:1234567890 320:1234567890 321:1234567890 322:1234567890 323:1234567890 324:1234567890 325:1234567890 326:1234567890 327:1234567890 328:1234567890 329:1234567890 330:1234567890 331:1234567890 332:1234567890 333:1234567890
delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 5058 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890 84:1234567890 85:1234567890 86:1234567890 87:1234567890 88:1234567890 89:1234567890 90:1234567890 91:1234567890 92:1234567890 93:1234567890 94:1234567890 95:1234567890 96:1234567890 97:1234567890 98:1234567890 99:1234567890 100:1234567890 101:1234567890 102:1234567890 103:1234567890 104:1234567890 105:1234567890 106:1234567890 107:1234567890 108:1234567890 109:1234567890 110:1234567890 111:1234567890 112:1234567890 113:1234567890 114:1234567890 115:1234567890 116:1234567890 117:1234567890 118:1234567890 119:1234567890 120:1234567890 121:1234567890 122:1234567890 123:1234567890 124:1234567890 125:1234567890 126:1234567890 127:1234567890 128:1234567890 129:1234567890 130:1234567890 131:1234567890 132:1234567890 133:1234567890 134:1234567890 135:1234567890 136:1234567890 137:1234567890 138:1234567890 139:1234567890 140:1234567890 141:1234567890 142:1234567890 143:1234567890 144:1234567890 145:1234567890 146:1234567890 147:1234567890 148:1234567890 149:1234567890 150:1234567890 151:1234567890 152:1234567890 153:1234567890 154:1234567890 155:1234567890 156:1234567890 157:1234567890 158:1234567890 159:1234567890 160:1234567890 161:1234567890 162:1234567890 163:1234567890 164:1234567890 165:1234567890 166:1234567890 167:12345678901234567890 168:1234567890 169:1234567890 170:1234567890 171:1234567890 172:1234567890 173:1234567890 174:1234567890 175:1234567890 176:1234567890 177:1234567890 178:1234567890 179:1234567890 180:1234567890 181:1234567890 182:1234567890 183:1234567890 184:1234567890 185:1234567890 186:1234567890 187:1234567890 188:1234567890 189:1234567890 190:1234567890 191:1234567890 192:1234567890 193:1234567890 194:1234567890 195:1234567890 196:1234567890 197:1234567890 198:1234567890 199:1234567890 200:1234567890 201:1234567890 202:1234567890 203:1234567890 204:1234567890 205:1234567890 206:1234567890 207:1234567890 208:1234567890 209:1234567890 210:1234567890 211:1234567890 212:1234567890 213:1234567890 214:1234567890 215:1234567890 216:1234567890 217:1234567890 218:1234567890 219:1234567890 220:1234567890 221:1234567890 222:1234567890 223:1234567890 224:1234567890 225:1234567890 226:1234567890 227:1234567890 228:1234567890 229:1234567890 230:1234567890 231:1234567890 232:1234567890 233:1234567890 234:1234567890 235:1234567890 236:1234567890 237:1234567890 238:1234567890 239:1234567890 240:1234567890 241:1234567890 242:1234567890 243:1234567890 244:1234567890 245:1234567890 246:1234567890 247:1234567890 248:1234567890 249:1234567890 250:12345678901234567890 251:1234567890 252:1234567890 253:1234567890 254:1234567890 255:1234567890 256:1234567890 257:1234567890 258:1234567890 259:1234567890 260:1234567890 261:1234567890 262:1234567890 263:1234567890 264:1234567890 265:1234567890 266:1234567890 267:1234567890 268:1234567890 269:1234567890 270:1234567890 271:1234567890 272:1234567890 273:1234567890 274:1234567890 275:1234567890 276:1234567890 277:1234567890 278:1234567890 279:1234567890 280:1234567890 281:1234567890 282:1234567890 283:1234567890 284:1234567890 285:1234567890 286:1234567890 287:1234567890 288:1234567890 289:1234567890 290:1234567890 291:1234567890 292:1234567890 293:1234567890 294:1234567890 295:1234567890 296:1234567890 297:1234567890 298:1234567890 299:1234567890 300:1234567890 301:1234567890 302:1234567890 303:1234567890 304:1234567890 305:1234567890 306:1234567890 307:1234567890 308:1234567890 309:1234567890 310:1234567890 311:1234567890 312:1234567890 313:1234567890 314:1234567890 315:1234567890 316:1234567890 317:1234567890 318:1234567890 319:1234567890 320:1234567890 321:1234567890 322:1234567890 323:1234567890 324:1234567890 325:1234567890 326:1234567890 327:1234567890 328:1234567890 329:1234567890 330:1234567890 331:1234567890 332:1234567890 333:12345678901234567890 334:1234567890 335:1234567890 336:1234567890 337:1234567890 338:1234567890 339:1234567890 340:1234567890 341:1234567890 342:1234567890 343:1234567890 344:1234567890 345:1234567890 346:1234567890 347:1234567890 348:1234567890 349:1234567890 350:1234567890 351:1234567890 352:1234567890 353:1234567890 354:1234567890 355:1234567890 356:1234567890 357:1234567890 358:1234567890 359:1234567890 360:1234567890 361:1234567890 362:1234567890 363:1234567890 364:1234567890 365:1234567890 366:1234567890 367:1234567890 368:1234567890 369:1234567890 370:1234567890 371:1234567890 372:1234567890 373:1234567890 374:1234567890 375:1234567890 376:1234567890 377:1234567890 378:1234567890 379:1234567890 380:1234567890 381:1234567890 382:1234567890 383:1234567890 384:1234567890 385:1234567890 386:1234567890 387:1234567890 388:1234567890 389:1234567890 390:1234567890 391:1234567890 392:1234567890 393:1234567890 394:1234567890 395:1234567890 396:1234567890 397:1234567890 398:1234567890 399:1234567890 400:1234567890 401:1234567890 402:1234567890 403:1234567890 404:1234567890 405:1234567890 406:1234567890 407:1234567890 408:1234567890 409:1234567890 410:1234567890 411:1234567890 412:1234567890 413:1234567890 414:1234567890 415:1234567890 416:1234567890
delimiter :[]: input string :1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]12345678901234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890[]1234567890: comment : 6040 characters long input string
0:1234567890 1:1234567890 2:1234567890 3:1234567890 4:1234567890 5:1234567890 6:1234567890 7:1234567890 8:1234567890 9:1234567890 10:1234567890 11:1234567890 12:1234567890 13:1234567890 14:1234567890 15:1234567890 16:1234567890 17:1234567890 18:1234567890 19:1234567890 20:1234567890 21:1234567890 22:1234567890 23:1234567890 24:1234567890 25:1234567890 26:1234567890 27:1234567890 28:1234567890 29:1234567890 30:1234567890 31:1234567890 32:1234567890 33:1234567890 34:1234567890 35:1234567890 36:1234567890 37:1234567890 38:1234567890 39:1234567890 40:1234567890 41:1234567890 42:1234567890 43:1234567890 44:1234567890 45:1234567890 46:1234567890 47:1234567890 48:1234567890 49:1234567890 50:1234567890 51:1234567890 52:1234567890 53:1234567890 54:1234567890 55:1234567890 56:1234567890 57:1234567890 58:1234567890 59:1234567890 60:1234567890 61:1234567890 62:1234567890 63:1234567890 64:1234567890 65:1234567890 66:1234567890 67:1234567890 68:1234567890 69:1234567890 70:1234567890 71:1234567890 72:1234567890 73:1234567890 74:1234567890 75:1234567890 76:1234567890 77:1234567890 78:1234567890 79:1234567890 80:1234567890 81:1234567890 82:1234567890 83:1234567890 84:1234567890 85:1234567890 86:1234567890 87:1234567890 88:1234567890 89:1234567890 90:1234567890 91:1234567890 92:1234567890 93:1234567890 94:1234567890 95:1234567890 96:1234567890 97:1234567890 98:1234567890 99:1234567890 100:1234567890 101:1234567890 102:1234567890 103:1234567890 104:1234567890 105:1234567890 106:1234567890 107:1234567890 108:1234567890 109:1234567890 110:1234567890 111:1234567890 112:1234567890 113:1234567890 114:1234567890 115:1234567890 116:1234567890 117:1234567890 118:1234567890 119:1234567890 120:1234567890 121:1234567890 122:1234567890 123:1234567890 124:1234567890 125:1234567890 126:1234567890 127:1234567890 128:1234567890 129:1234567890 130:1234567890 131:1234567890 132:1234567890 133:1234567890 134:1234567890 135:1234567890 136:1234567890 137:1234567890 138:1234567890 139:1234567890 140:1234567890 141:1234567890 142:1234567890 143:1234567890 144:1234567890 145:1234567890 146:1234567890 147:1234567890 148:1234567890 149:1234567890 150:1234567890 151:1234567890 152:1234567890 153:1234567890 154:1234567890 155:1234567890 156:1234567890 157:1234567890 158:1234567890 159:1234567890 160:1234567890 161:1234567890 162:1234567890 163:1234567890 164:1234567890 165:1234567890 166:1234567890 167:12345678901234567890 168:1234567890 169:1234567890 170:1234567890 171:1234567890 172:1234567890 173:1234567890 174:1234567890 175:1234567890 176:1234567890 177:1234567890 178:1234567890 179:1234567890 180:1234567890 181:1234567890 182:1234567890 183:1234567890 184:1234567890 185:1234567890 186:1234567890 187:1234567890 188:1234567890 189:1234567890 190:1234567890 191:1234567890 192:1234567890 193:1234567890 194:1234567890 195:1234567890 196:1234567890 197:1234567890 198:1234567890 199:1234567890 200:1234567890 201:1234567890 202:1234567890 203:1234567890 204:1234567890 205:1234567890 206:1234567890 207:1234567890 208:1234567890 209:1234567890 210:1234567890 211:1234567890 212:1234567890 213:1234567890 214:1234567890 215:1234567890 216:1234567890 217:1234567890 218:1234567890 219:1234567890 220:1234567890 221:1234567890 222:1234567890 223:1234567890 224:1234567890 225:1234567890 226:1234567890 227:1234567890 228:1234567890 229:1234567890 230:1234567890 231:1234567890 232:1234567890 233:1234567890 234:1234567890 235:1234567890 236:1234567890 237:1234567890 238:1234567890 239:1234567890 240:1234567890 241:1234567890 242:1234567890 243:1234567890 244:1234567890 245:1234567890 246:1234567890 247:1234567890 248:1234567890 249:1234567890 250:12345678901234567890 251:1234567890 252:1234567890 253:1234567890 254:1234567890 255:1234567890 256:1234567890 257:1234567890 258:1234567890 259:1234567890 260:1234567890 261:1234567890 262:1234567890 263:1234567890 264:1234567890 265:1234567890 266:1234567890 267:1234567890 268:1234567890 269:1234567890 270:1234567890 271:1234567890 272:1234567890 273:1234567890 274:1234567890 275:1234567890 276:1234567890 277:1234567890 278:1234567890 279:1234567890 280:1234567890 281:1234567890 282:1234567890 283:1234567890 284:1234567890 285:1234567890 286:1234567890 287:1234567890 288:1234567890 289:1234567890 290:1234567890 291:1234567890 292:1234567890 293:1234567890 294:1234567890 295:1234567890 296:1234567890 297:1234567890 298:1234567890 299:1234567890 300:1234567890 301:1234567890 302:1234567890 303:1234567890 304:1234567890 305:1234567890 306:1234567890 307:1234567890 308:1234567890 309:1234567890 310:1234567890 311:1234567890 312:1234567890 313:1234567890 314:1234567890 315:1234567890 316:1234567890 317:1234567890 318:1234567890 319:1234567890 320:1234567890 321:1234567890 322:1234567890 323:1234567890 324:1234567890 325:1234567890 326:1234567890 327:1234567890 328:1234567890 329:1234567890 330:1234567890 331:1234567890 332:1234567890 333:12345678901234567890 334:1234567890 335:1234567890 336:1234567890 337:1234567890 338:1234567890 339:1234567890 340:1234567890 341:1234567890 342:1234567890 343:1234567890 344:1234567890 345:1234567890 346:1234567890 347:1234567890 348:1234567890 349:1234567890 350:1234567890 351:1234567890 352:1234567890 353:1234567890 354:1234567890 355:1234567890 356:1234567890 357:1234567890 358:1234567890 359:1234567890 360:1234567890 361:1234567890 362:1234567890 363:1234567890 364:1234567890 365:1234567890 366:1234567890 367:1234567890 368:1234567890 369:1234567890 370:1234567890 371:1234567890 372:1234567890 373:1234567890 374:1234567890 375:1234567890 376:1234567890 377:1234567890 378:1234567890 379:1234567890 380:1234567890 381:1234567890 382:1234567890 383:1234567890 384:1234567890 385:1234567890 386:1234567890 387:1234567890 388:1234567890 389:1234567890 390:1234567890 391:1234567890 392:1234567890 393:1234567890 394:1234567890 395:1234567890 396:1234567890 397:1234567890 398:1234567890 399:1234567890 400:1234567890 401:1234567890 402:1234567890 403:1234567890 404:1234567890 405:1234567890 406:1234567890 407:1234567890 408:1234567890 409:1234567890 410:1234567890 411:1234567890 412:1234567890 413:1234567890 414:1234567890 415:1234567890 416:1234567890 417:1234567890 418:1234567890 419:1234567890 420:1234567890 421:1234567890 422:1234567890 423:1234567890 424:1234567890 425:1234567890 426:1234567890 427:1234567890 428:1234567890 429:1234567890 430:1234567890 431:1234567890 432:1234567890 433:1234567890 434:1234567890 435:1234567890 436:1234567890 437:1234567890 438:1234567890 439:1234567890 440:1234567890 441:1234567890 442:1234567890 443:1234567890 444:1234567890 445:1234567890 446:1234567890 447:1234567890 448:1234567890 449:1234567890 450:1234567890 451:1234567890 452:1234567890 453:1234567890 454:1234567890 455:1234567890 456:1234567890 457:1234567890 458:1234567890 459:1234567890 460:1234567890 461:1234567890 462:1234567890 463:1234567890 464:1234567890 465:1234567890 466:1234567890 467:1234567890 468:1234567890 469:1234567890 470:1234567890 471:1234567890 472:1234567890 473:1234567890 474:1234567890 475:1234567890 476:1234567890 477:1234567890 478:1234567890 479:1234567890 480:1234567890 481:1234567890 482:1234567890 483:1234567890 484:1234567890 485:1234567890 486:1234567890 487:1234567890 488:1234567890 489:1234567890 490:1234567890 491:1234567890 492:1234567890 493:1234567890 494:1234567890 495:1234567890 496:1234567890 497:1234567890 498:1234567890 499:1234567890 500:1234567890

test of 7048 and 8040 string removed due to hitting character limit
This is also very fast for what it is !

Soon I will have the perfect pure batch :split !

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#6 Post by shodan » 25 May 2024 21:40

Latest improvements of my split function

It's a lot less convoluted and much faster

Still breaks on poison characters however.

still need to implement, multiple delimiters, optional startindex, optional limit, loosen up the parameters
at least to allow CASESENSITIVE anywhere.
After that it will need the ability to return only the Nth element,
after that the ability to return an element range

chatgpt also suggests adding these

ChatGPT
Sure, here are some additional features that are commonly found in split functions in various programming languages, which you might consider adding to your batch script split function:

1. **Trim Whitespace**:
- **Functionality**: Automatically trim leading and trailing whitespace from each split element.

2. **Exclude Empty Elements**:
- **Functionality**: Option to exclude empty elements from the result array. This can be useful when dealing with delimiters that might result in consecutive empty strings.

3. **Escape Character Support**:
- **Functionality**: Support for escape characters to allow delimiters to be part of the split elements.

4. **Regex Support for Delimiters**:
- **Functionality**: Allow regular expressions as delimiters for more complex splitting logic.

5. **Reverse Split**:
- **Functionality**: Split the string from the end rather than the beginning.

6. **Capture Delimiters**:
- **Functionality**: Option to include the delimiters in the output array along with the split elements.

7. **Preserve Quoted Strings**:
- **Functionality**: Option to treat quoted strings as single elements, even if they contain delimiters.

8. **Custom Function for Each Element**:
- **Functionality**: Allow a custom function or script to be applied to each split element before storing it in the output array.

9. **Split into Pairs**:
- **Functionality**: Split the string into pairs of elements (key-value pairs), which can be useful for parsing configuration strings or command-line arguments.

10. **Multi-character Delimiters with Overlap**:
- **Functionality**: Handle cases where multi-character delimiters can overlap in the input string.


I'm also thinking splitting into a multi dimension array like [0,0,0,0] with [COLUMN] [ROW] [TABLE] [CUBE]

9. **Output Array Dimensions**:
- Functionality: Ability to specify that different delimiters output to different dimensions, e.g., splitting by rows and columns.

5. **Get Range of Elements**:
- Functionality: Ability to specify a range of elements to return, e.g., "2,3,4-8,28".


Code: Select all

REM this will need a startindex probably, to start at a certain position in the string
::Usage Call :split InputString Delimiter OutputArray optional limit [CASESENSITIVE]
:Split
set "_Split_prefix=_SPLT"
set "_SPLT_CaseSensitivity=/i"
set "_SPLT_Input=%~1"
set "_SPLT_Delimiter=%~2"
set "_SPLT_Output=%~3"
shift & shift & shift
echo.%~1| findstr /r "[^0123456789]" >nul && ( set /a _SPLT_Limit=%~1 & shift )
if "[%~1]" EQU "[CASESENSITIVE]" set "_SPLT_CaseSensitivity="
setlocal enabledelayedexpansion
set "_SPLT_localscope=true"
set "_SPLT_Input_Pointer=_SPLT_Input" 
set "_SPLT_Delimiter_Pointer=_SPLT_Delimiter"
if defined !_SPLT_Input! ( set "_SPLT_Input_Pointer=!_SPLT_Input!" )
if defined !_SPLT_Delimiter! ( set "_SPLT_Delimiter_Pointer=!_SPLT_Delimiter!" )
REM if defined !_SPLT_Delimiter!.ubound set /a _SPLT_Delimiter_ubound=!%_SPLT_Delimiter%.ubound!
REM if defined !_SPLT_Delimiter!.ubound set "_SPLT_Delimiter_Pointer=!_SPLT_Delimiter![!%_SPLT_Delimiter%.lbound!]"
if defined %_SPLT_Output%.ubound set /a _SPLT_Output_ubound=!%_SPLT_Output%.ubound!
if not defined _SPLT_Output_ubound set /a _SPLT_Output_ubound=-1
Call :len "%_SPLT_Input_Pointer%" _SPLT_Input_len
Call :len "%_SPLT_Delimiter_Pointer%" _SPLT_Delimiter_len
REM if not defined !_SPLT_Delimiter!.ubound GoTo :Split-get-delimiter-len-skip
REM :Split-get-delimiter-len-loop
REM FOR EACH DELIMITER, FIND DELIMITER.LEN
REM :Split-get-delimiter-len-skip
REM if defined _SPLT_Delimiter_ubound set /a _SPLT_Delimiter_index=0
REM :Split-delimiter-loop ?
set /a _SPLT_StartIndex=0
set /a _SPLT_Index=0
set "_SPLT_Search=!%_SPLT_Delimiter_Pointer%!"
:Split-loop
set /a _SPLT_remaining_input_len=%_SPLT_Input_len%-%_SPLT_Index%
if %_SPLT_remaining_input_len% LSS 64 ( set /a _SPLT_Search_Window_len=%_SPLT_remaining_input_len% ) else ( set /a _SPLT_Search_Window_len=64 )
:Split-substring-pre-loop
set _SPLT_CurrentWindow=!%_SPLT_Input_Pointer%:~%_SPLT_Index%,%_SPLT_Search_Window_len%!
set _SPLT_CurrentWindowResult=!_SPLT_CurrentWindow:%_SPLT_Search%=!
if %_SPLT_CaseSensitivity% !_SPLT_CurrentWindow! EQU !_SPLT_CurrentWindowResult! ( if %_SPLT_Search_Window_len% GEQ %_SPLT_remaining_input_len% ( set /a _SPLT_Index=%_SPLT_Input_len% & GoTo :Split-substring-end ) else ( set /a _SPLT_Index=%_SPLT_Index%+%_SPLT_Search_Window_len%-1 & set /a _SPLT_Search_Window_len=%_SPLT_Search_Window_len%*2 & GoTo :Split-substring-pre-loop ) )
set /a _SPLT_Search_Window_len=%_SPLT_Search_Window_len%/2
:Split-substring-loop
set /a _SPLT_Actual_Search_Window_len=%_SPLT_Search_Window_len%+%_SPLT_Delimiter_len%-1
set _SPLT_CurrentWindow=!%_SPLT_Input_Pointer%:~%_SPLT_Index%,%_SPLT_Actual_Search_Window_len%!
set _SPLT_CurrentWindowResult=!_SPLT_CurrentWindow:%_SPLT_Search%=!
REM set _SPLT
if %_SPLT_CaseSensitivity% !_SPLT_CurrentWindow! NEQ !_SPLT_CurrentWindowResult! ( if %_SPLT_Search_Window_len% EQU 1 ( GoTo :Split-substring-end ) else ( set /a _SPLT_Search_Window_len=%_SPLT_Search_Window_len%/2 ) ) else ( set /a _SPLT_Index=%_SPLT_Index%+%_SPLT_Search_Window_len% )
GoTo :Split-substring-loop 
:Split-substring-end
if %_SPLT_Index% EQU -1 ( set /a _SPLT_Len=%_SPLT_Input_len%-%_SPLT_Index% ) else ( set /a _SPLT_Len=%_SPLT_Index%-%_SPLT_StartIndex% )
set /a _SPLT_Output_ubound+=1
REM echo set "%_SPLT_Output%[%_SPLT_Output_ubound%]=^!%_SPLT_Input_Pointer%:~%_SPLT_StartIndex%,%_SPLT_Len%^!"
set "%_SPLT_Output%[%_SPLT_Output_ubound%]=!%_SPLT_Input_Pointer%:~%_SPLT_StartIndex%,%_SPLT_Len%!"
REM if %_SPLT_Delimiter_index% LEQ %_SPLT_Delimiter_ubound% GoTo :Split-delimiter-loop
set /a _SPLT_StartIndex=%_SPLT_Index%+%_SPLT_Delimiter_len%
set /a _SPLT_Index=%_SPLT_StartIndex%
if %_SPLT_Index% LSS %_SPLT_Input_len% GoTo :Split-loop
set /a %_SPLT_Output%.ubound=%_SPLT_Output_ubound%
for /F "delims=" %%a in ('set %_SPLT_Output%') do (
	endlocal
	set "%%a"
	)
if defined _SPLT_localscope endlocal
Call :ClearVariablesByPrefix %_Split_prefix% _Split_prefix  & exit /b %_SPLT_count%
REM thanks to https://stackoverflow.com/questions/49041934/how-to-return-an-array-of-values-across-endlocal https://stackoverflow.com/a/49042678

Here is the current version of the test file
GetSubstringIndex-DEMO.zip
(9.89 KiB) Downloaded 1010 times

Sponge Belly
Posts: 231
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#7 Post by Sponge Belly » 02 Jun 2024 13:04

Hi Shodan,

Very ambitious! But what is your use-case? And why are you re-inventing the wheel? Just pass the string to JScript or PowerShell in an environment variable, let it chop up the string any way you want, and capture the output in an for /f loop.

Laters! :)

- SB

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#8 Post by shodan » 03 Jun 2024 01:32

Hi,

For now I just want a split function that can take multiple delimiters, maybe if that's not too hard, multiple dimension arrays, then I'll see what else from the list I can add.

I want to try avoiding powershell as I try to make scripts that should run anywhere windows 2000 and up.

Also I would like to keep them pure batch if possible.

This is all for my "batchfile framework" project.
Which is mostly about making it easier to make batch files.
In particular it is about maintaining a library of batch functions as files you can directly call from the command line.

I need a way to copy a function from one batch file to the next.
Find which function calls a batch function needs
scan a batch file for all the needed function
add every needed function to a batch file from the library
and update a batch file to the latest version of the functions in the library

I just made a better version of the ReplaceString function.
This was to create test variables for testing the split function

Here is that function now
InsertString-demo.zip
(2.35 KiB) Downloaded 982 times

Code: Select all

::Usage Call :DeleteString InputString OutputString StartIndex DeleteLength [REPEAT Count]|[ALL] ... InsertIndexN InsertStringN [REPEAT [Count]] 
:DeleteString
set "_IS_ReplaceMode=true"
set "_IS_DeleteMode=true"
GoTo :InsertString
::Usage Call :ReplaceString InputString OutputString InsertIndex1 InsertString1 [REPEAT Count]|[ALL] ... InsertIndexN InsertStringN [REPEAT [Count]] 
:ReplaceString
set "_IS_ReplaceMode=true"
::Usage Call :InsertString InputString OutputString InsertIndex1 InsertString1 [REPEAT Count]|[ALL] ... InsertIndexN InsertStringN [REPEAT [Count]] 
:InsertString
set "_InsertString_prefix=_IS"
setlocal enabledelayedexpansion
set "_IS_LocalScope=true"
set "_IS_InputString=%~1"
set "_IS_OutputString=%~2"
if defined !_IS_OutputString! set "_IS_ResidualOutput=!_IS_OutputString!"
shift & shift 
:InsertString-args
set /a _IS_InsertIndex=%~1 2>nul
set "_IS_InsertString=%~2"
REM if defined _IS_DeleteMode for /L %%a in (1,1,%_IS_InsertString%) do ( set "_IS_InsertString=!_IS_InsertString! " )
shift & shift
set /a _IS_InsertCountIndex=0 & if "[%~1]" EQU "[REPEAT]" ( set /a _IS_InsertCount=%~2 & shift & shift ) else ( set /a _IS_InsertCount=-1 )
if "[%~1]" EQU "[ALL]" ( set "_IS_AllTheString=true" & shift )
set "_IS_InputString_Pointer=_IS_InputString" & if defined !_IS_InputString! set "_IS_InputString_Pointer=!_IS_InputString!"
set "_IS_InsertString_Pointer=_IS_InsertString" & if defined !_IS_InsertString! set "_IS_InsertString_Pointer=!_IS_InsertString!"
if defined _IS_DeleteMode set "_IS_InsertString_Pointer=_IS_Blank"
REM if not defined _IS_InsertIndex set /a _IS_InsertIndex=0
set /a _IS_StartIndex=0
set /a _IS_InsertString_Pointer_len=0 & if defined _IS_ReplaceMode call :len !_IS_InsertString_Pointer! _IS_InsertString_Pointer_len
if defined _IS_DeleteMode set /a _IS_InsertString_Pointer_len=%_IS_InsertString%
set /a _IS_NextIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
:InsertString-count-loop
if "[!%_IS_InputString_Pointer%:~%_IS_NextIndex%!]" EQU "[]" GoTo :InsertString-count-end
set "_IS_NewOutput=!_IS_NewOutput!!%_IS_InputString_Pointer%:~%_IS_StartIndex%,%_IS_InsertIndex%!!%_IS_InsertString_Pointer%!"
set /a _IS_StartIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
set /a _IS_NextIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
if %_IS_InsertCountIndex% LSS %_IS_InsertCount% (  set /a _IS_InsertCountIndex+=1 & GoTo :InsertString-count-loop )
if defined _IS_AllTheString GoTo :InsertString-count-loop
:InsertString-count-end
set "_IS_NewOutput=!_IS_ResidualOutput!!_IS_NewOutput!!%_IS_InputString_Pointer%:~%_IS_StartIndex%!" & set "_IS_ResidualOutput="
if "[%~1]" NEQ "[]" ( set "_IS_InputString=!_IS_NewOutput!" & set "_IS_NewOutput=" &  GoTo :InsertString-args )
for /f "tokens=1* delims=" %%a in ('echo.!_IS_NewOutput!') do endlocal & set %_IS_OutputString%=%%a
if defined _IS_LocalScope endlocal
Call :ClearVariablesByPrefix %_InsertString_prefix% _InsertString_prefix & GoTo :EOF
Here are demo function to demonstrate how it works, console output below

Code: Select all

:InsertString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[1] 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[2] 10 " ABC " REPEAT 0
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[3] 10 " ABC " REPEAT 1
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[4] 10 " ABC " REPEAT 2
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[5] 10 " ABC " REPEAT 3
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[6] 10 " ABC " REPEAT 4
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[7] 10 " ABC " REPEAT 5
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[8] 10 " ABC " REPEAT 6
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[9] 10 " ABC " REPEAT 7
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[10] 10 " ABC " REPEAT 8
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[11] 10 " ABC " REPEAT 9
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[12] 10 " ABC " REPEAT 10
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[13] 10 " ABC " REPEAT 11
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[14] 10 " ABC " ALL
set /a _InsertString_demo_output.ubound=14
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString

Call :ReplaceString-demo
Call :DeleteString-demo

GoTo :EOF

Code: Select all

:ReplaceString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[1] 10 " ABC "
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[2] 10 " ABC " REPEAT 0
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[3] 10 " ABC " REPEAT 1
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[4] 10 " ABC " REPEAT 2
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[5] 10 " ABC " REPEAT 3
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[6] 10 " ABC " REPEAT 4
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[7] 10 " ABC " REPEAT 5
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[8] 10 " ABC " REPEAT 6
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[9] 10 " ABC " REPEAT 7
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[10] 10 " ABC " REPEAT 8
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[11] 10 " ABC " REPEAT 9
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[12] 10 " ABC " REPEAT 10
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[13] 10 " ABC " REPEAT 11
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[14] 10 " ABC " ALL
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[15] 10 " ABC " 25 " DEF " 40 " GHI " 55 " KLM "
set /a _InsertString_demo_output.ubound=15
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString
GoTo :EOF

Code: Select all

:DeleteString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[1] 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[2] 10 5 REPEAT 0
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[3] 10 5 REPEAT 1
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[4] 10 5 REPEAT 2
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[5] 10 5 REPEAT 3
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[6] 10 5 REPEAT 4
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[7] 10 5 REPEAT 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[8] 10 5 REPEAT 6
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[9] 10 5 REPEAT 7
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[10] 10 5 REPEAT 8
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[11] 10 5 REPEAT 9
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[12] 10 5 REPEAT 10
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[13] 10 5 REPEAT 11
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[14] 10 5 ALL
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[15] 10 5 25 5 40 5 55 5
set /a _InsertString_demo_output.ubound=15
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString
GoTo :EOF

Code: Select all

InsertString-demo.bat

A123456789 ABC B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789

A123456789 ABC 56789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 DEF D123456789 GHI 56789F1234 KLM G123456789H123456789I123456789J123456789

A12345678956789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F1234G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I123456789J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C12345678956789E12345678956789G12345678956789I123456789J123456789

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#9 Post by shodan » 09 Jun 2024 19:52

Improved version of :ReplaceString :InsertString :DeleteString

Code: Select all

::Usage Call :DeleteString InputString OutputString [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndex1 InsertString1  ... [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndexN InsertStringN
:DeleteString
set "_IS_ReplaceMode=true"
set "_IS_DeleteMode=true"
GoTo :InsertString
::Usage Call :ReplaceString InputString OutputString [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndex1 InsertString1  ... [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndexN InsertStringN
:ReplaceString
set "_IS_ReplaceMode=true"
::Usage Call :InsertString InputString OutputString [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndex1 InsertString1  ... [REPEAT Count]|[ALL][APPEND][OVERSPLIT][LEN DelimiterLen][RESET] InsertIndexN InsertStringN
:InsertString
set "_InsertString_prefix=_IS"
setlocal enabledelayedexpansion
if "[%~1]" EQU "[APPEND]" ( set "_IS_AppendMode=true" & shift)
set "_IS_LocalScope=true"
set "_IS_InputString=%~1"
set "_IS_OutputString=%~2"
if defined _IS_AppendMode if defined !_IS_OutputString! set "_IS_ResidualOutput=!_IS_OutputString!"
set /a _IS_InsertCountIndex=0
set /a _IS_InsertCount=-1
:InsertString-args
if "[%~3]" EQU "[REPEAT]" ( for /f "tokens=1,2 delims=," %%a in ("%~4") do ( set /a _IS_InsertCount=%%a & set /a _IS_InsertSkip=%%b 2>nul ) & shift & shift & GoTo :InsertString-args )
if "[%~3]" EQU "[ALL]" ( set "_IS_AllTheString=true" & shift & GoTo :InsertString-args )
if "[%~3]" EQU "[OVERSPLIT]" ( set "_IS_Oversplit=true" & shift & GoTo :InsertString-args )
if "[%~3]" EQU "[LEN]" ( set /a _IS_InsertString_Pointer_len=%~4 & shift & shift & GoTo :InsertString-args )
if "[%~3]" EQU "[RESET]" ( set "_IS_Oversplit=" & set "_IS_InsertString_Pointer_len=" & set "_IS_Oversplit=" & set "_IS_InsertCount=" & set "_IS_InsertSkip=" & shift & GoTo :InsertString-args )
if defined _IS_AllTheString set "_IS_Oversplit="
set /a _IS_InsertIndex=%~3
set "_IS_InsertString=%~4"
shift & shift
set "_IS_InputString_Pointer=_IS_InputString" & if defined !_IS_InputString! set "_IS_InputString_Pointer=!_IS_InputString!"
set "_IS_InsertString_Pointer=_IS_InsertString" & if defined !_IS_InsertString! set "_IS_InsertString_Pointer=!_IS_InsertString!"
if defined _IS_DeleteMode set "_IS_InsertString_Pointer=_IS_Blank"
if not defined _IS_InsertString_Pointer_len ( set /a _IS_InsertString_Pointer_len=0 & if defined _IS_ReplaceMode call :len !_IS_InsertString_Pointer! _IS_InsertString_Pointer_len )
if defined _IS_DeleteMode set /a _IS_InsertString_Pointer_len=%_IS_InsertString%
set /a _IS_StartIndex=0
set /a _IS_NextIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
:InsertString-count-loop
if not defined _IS_Oversplit if "[!%_IS_InputString_Pointer%:~%_IS_NextIndex%!]" EQU "[]" GoTo :InsertString-count-end
set "_IS_NewOutput=!_IS_NewOutput!!%_IS_InputString_Pointer%:~%_IS_StartIndex%,%_IS_InsertIndex%!!%_IS_InsertString_Pointer%!"
set /a _IS_StartIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
if defined _IS_InsertSkip set /a _IS_InsertIndex=%_IS_InsertSkip%
set /a _IS_NextIndex=%_IS_StartIndex%+%_IS_InsertIndex%+%_IS_InsertString_Pointer_len%
if %_IS_InsertCountIndex% LSS %_IS_InsertCount% (  set /a _IS_InsertCountIndex+=1 & GoTo :InsertString-count-loop )
if defined _IS_AllTheString GoTo :InsertString-count-loop
:InsertString-count-end
set "_IS_NewOutput=!_IS_ResidualOutput!!_IS_NewOutput!!%_IS_InputString_Pointer%:~%_IS_StartIndex%!" & set "_IS_ResidualOutput="
if "[%~3]" NEQ "[]" ( set "_IS_InputString=!_IS_NewOutput!" & set "_IS_NewOutput=" & set "_IS_Oversplit=" & set "_IS_InsertString_Pointer_len=" & set "_IS_Oversplit=" & set "_IS_InsertCount=" & set "_IS_InsertSkip=" & GoTo :InsertString-args )
for /f "tokens=1* delims=" %%a in ("!_IS_NewOutput!") do ( endlocal & set %_IS_OutputString%=%%a )
if defined _IS_LocalScope endlocal
Call :ClearVariablesByPrefix %_InsertString_prefix% _InsertString_prefix & GoTo :EOF

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#10 Post by shodan » 09 Jun 2024 19:54

Here is the new demo for these functions

demo file
InsertString-demo.zip
(2.48 KiB) Downloaded 1016 times

Code: Select all

:InsertString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[1] 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[2] REPEAT 0 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[3] REPEAT 1 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[4] REPEAT 2 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[5] REPEAT 3 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[6] REPEAT 4 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[7] REPEAT 5 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[8] REPEAT 6 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[9] REPEAT 7 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[10] REPEAT 8 10 " ABC "
set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789"
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[11] REPEAT 9 10 " ABC "
set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[12] REPEAT 10 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[13] REPEAT 11 10 " ABC "
Call :InsertString _InsertString_demo_testvar _InsertString_demo_output[14] ALL 10 " ABC "
set /a _InsertString_demo_output.ubound=14
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString

Call :ReplaceString-demo
Call :DeleteString-demo

GoTo :EOF

:ReplaceString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[1] 10 " ABC "
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[2] REPEAT 0 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[3] REPEAT 1 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[4] REPEAT 2 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[5] REPEAT 3 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[6] REPEAT 4 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[7] REPEAT 5 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[8] REPEAT 6 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[9] REPEAT 7 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[10] REPEAT 8 10 " ABC " 
set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789"
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[11] REPEAT 9 10 " ABC " 
set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[12] REPEAT 10 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[13] REPEAT 11 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[14] ALL 10 " ABC " 
Call :ReplaceString _InsertString_demo_testvar _InsertString_demo_output[15] 10 " ABC " 25 " DEF " 40 " GHI " 55 " KLM "
set /a _InsertString_demo_output.ubound=15
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString
GoTo :EOF

:DeleteString-demo

set "_InsertString_demo_testvar=A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789"

REM Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[0] 10
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[1] 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[2] REPEAT 0 10 5 
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[3] REPEAT 1 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[4] REPEAT 2 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[5] REPEAT 3 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[6] REPEAT 4 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[7] REPEAT 5 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[8] REPEAT 6 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[9] REPEAT 7 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[10] REPEAT 8 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[11] REPEAT 9 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[12] REPEAT 10 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[13] REPEAT 11 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[14] ALL 10 5
Call :DeleteString _InsertString_demo_testvar _InsertString_demo_output[15] 10 5 25 5 40 5 55 5
set /a _InsertString_demo_output.ubound=15
Call :EchoArray _InsertString_demo_output

Call :ClearVariablesByPrefix  _InsertString
GoTo :EOF

Here is the output of that

InsertString-demo.bat

Code: Select all

A123456789 ABC B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789 ABC K123456789L123456789M123456789N123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789
A123456789 ABC B123456789 ABC C123456789 ABC D123456789 ABC E123456789 ABC F123456789 ABC G123456789 ABC H123456789 ABC I123456789 ABC J123456789

A123456789 ABC 56789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F123456789G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789H123456789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I123456789J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789 ABC 56789L1234 ABC M123456789 ABC 56789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 ABC D123456789 ABC 56789F1234 ABC G123456789 ABC 56789I1234 ABC J123456789
A123456789 ABC 56789C1234 DEF D123456789 GHI 56789F1234 KLM G123456789H123456789I123456789J123456789

A12345678956789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D123456789E123456789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F123456789G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F1234G123456789H123456789I123456789J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I123456789J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C1234D12345678956789F1234G12345678956789I1234J123456789
A12345678956789C12345678956789E12345678956789G12345678956789I123456789J123456789

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#11 Post by shodan » 10 Jun 2024 04:39

Updated :GetSubstringIndex

Should now support multiple delimiters of any lengths, not sure what the limits are

new test file, which includes tests based on GetTestArray
Next I should have a proper split working !
GetSubstringIndex-DEMO.zip
(12.01 KiB) Downloaded 9402 times

Code: Select all

REM [NODEREFERENCE] to disable byref
::Usage Call :GetSubstringIndex [CASESENSITIVE] InputString optional StartIndex optional [OUTPUT OutputIndexVar] Delimiter1 Delimiter2 ... DelimiterN ??... InputStringN SearchStringN StartIndexN Optional OutputIndexVar
::Usage Call :GetSubstringIndex InputString SearchString optional StartIndex OutputIndexVar ... InputStringN SearchStringN StartIndexN Optional OutputIndexVar
:GetSubstringIndex
set "_GetSubstringIndex_prefix=_GSSI"
setlocal enabledelayedexpansion
set "_GSSI_CaseSensitivity=/i"
:GetSubstringIndex-args
if "[%~1]" EQU "[CASESENSITIVE]" ( set "_GSSI_CaseSensitivity=" & shift & GoTo :GetSubstringIndex-args )
if "[%~1]" EQU "[OUTPUT]" ( set "_GSSI_Output=%~2" & shift & shift & GoTo :GetSubstringIndex-args )
if not defined _GSSI_Input ( set "_GSSI_Input=%~1" & shift & GoTo :GetSubstringIndex-args )
echo.%~1| findstr /r "[^0123456789]" >nul || ( echo isnum "%~1" & set /a _GSSI_StartIndex=%~1 & shift )
set /a _GSSI_Delimiter.ubound=-1
:GetSubstringIndex-delimiters-args
set "_GSSI_Buffer=%~1"
REM if defined _GSSI_Buffer if "[%_GSSI_Buffer:~1,3%]" EQU "[DIM]" if "[%_GSSI_Buffer%]" EQU "[]" ( set /a _GSSI_Delimiter_Dimension=%_GSSI_Buffer:~0,1% )
REM if defined _GSSI_Buffer if "[%_GSSI_Buffer:~4,1%]" EQU "[]" ( set /a _GSSI_Delimiter_Dimension=%_GSSI_Buffer:~0,1% 2>nul )
if defined %~1.ubound ( set "_GSSI_Delimiter_is_array=true" )
set /a _GSSI_Delimiter.index=0
if defined %~1.ubound ( set /a _GSSI_Delimiter_input_array_ubound=!%~1.ubound! 2>nul ) else ( set /a _GSSI_Delimiter_input_array_ubound=-1 )
:GetSubstringIndex-delimiters-loop-args
if "[%~1]" NEQ "[]" set /a _GSSI_Delimiter.ubound+=1
if "[%~1]" NEQ "[]" if defined _GSSI_Delimiter_is_array set "_GSSI_Delimiter[%_GSSI_Delimiter.ubound%]=!%~1[%_GSSI_Delimiter.index%]!"
REM if "[%~1]" NEQ "[]" if defined _GSSI_Delimiter_is_array echo _GSSI_Delimiter_is_array is defined 
REM if "[%~1]" NEQ "[]" if not defined _GSSI_Delimiter_is_array echo set "_GSSI_Delimiter[%_GSSI_Delimiter.ubound%]=%~1"
if "[%~1]" NEQ "[]" if not defined _GSSI_Delimiter_is_array set "_GSSI_Delimiter[%_GSSI_Delimiter.ubound%]=%~1"
REM if "[%~1]" NEQ "[]" if not defined _GSSI_Delimiter_is_array echo _GSSI_Delimiter_is_array is not defined
if defined _GSSI_Delimiter_is_array set /a _GSSI_Delimiter.index+=1
if defined _GSSI_Delimiter_is_array if %_GSSI_Delimiter.index% LEQ %_GSSI_Delimiter_input_array_ubound% ( GoTo :GetSubstringIndex-delimiters-loop-args )
set "_GSSI_Delimiter.index=" & set "_GSSI_Delimiter_is_array=" & if "[%~2]" NEQ "[]" ( shift & GoTo :GetSubstringIndex-delimiters-args )
set /a _GSSI_Delimiter.index=0
set "_GSSI_Input_Pointer=_GSSI_Input" & if defined !_GSSI_Input! ( set "_GSSI_Input_Pointer=!_GSSI_Input!" )
Call :len "%_GSSI_Input_Pointer%" _GSSI_Input_len
if not defined _GSSI_StartIndex set /a _GSSI_StartIndex=0
:GetSubstringIndex-loop
set /a _GSSI_Index=%_GSSI_StartIndex%
set "_GSSI_Delimiter_Pointer=_GSSI_Delimiter[%_GSSI_Delimiter.ubound%]" 
if defined !%_GSSI_Delimiter_Pointer%! ( set "_GSSI_Delimiter_Pointer=!%_GSSI_Delimiter_Pointer%!" )
Call :len "%_GSSI_Delimiter_Pointer%" _GSSI_Delimiter_len
set "_GSSI_Search=!%_GSSI_Delimiter_Pointer%!"
set /a _GSSI_remaining_input_len=%_GSSI_Input_len%-%_GSSI_Index%
if %_GSSI_remaining_input_len% LSS 64 ( set /a _GSSI_Search_Window_len=%_GSSI_remaining_input_len% ) else ( set /a _GSSI_Search_Window_len=64 )
:GetSubstringIndex-substring-pre-loop
set /a _GSSI_Actual_Search_Window_len=%_GSSI_Search_Window_len%+%_GSSI_Delimiter_len%-1
set "_GSSI_CurrentWindow=!%_GSSI_Input_Pointer%:~%_GSSI_Index%,%_GSSI_Actual_Search_Window_len%!"
set "_GSSI_CurrentWindowResult=!_GSSI_CurrentWindow:%_GSSI_Search%=!"
if %_GSSI_CaseSensitivity% "!_GSSI_CurrentWindow!" EQU "!_GSSI_CurrentWindowResult!" ( if %_GSSI_Search_Window_len% GEQ %_GSSI_remaining_input_len% ( set /a _GSSI_Index=%_GSSI_Input_len% & GoTo :GetSubstringIndex-substring-end ) else ( set /a _GSSI_Index=%_GSSI_Index%+%_GSSI_Search_Window_len%-1 & set /a _GSSI_Search_Window_len=%_GSSI_Search_Window_len%*2 & GoTo :GetSubstringIndex-substring-pre-loop ) )
set /a _GSSI_Search_Window_len=%_GSSI_Search_Window_len%/2
:GetSubstringIndex-substring-loop
set /a _GSSI_Actual_Search_Window_len=%_GSSI_Search_Window_len%+%_GSSI_Delimiter_len%-1
set "_GSSI_CurrentWindow=!%_GSSI_Input_Pointer%:~%_GSSI_Index%,%_GSSI_Actual_Search_Window_len%!"
set "_GSSI_CurrentWindowResult=!_GSSI_CurrentWindow:%_GSSI_Search%=!"
if %_GSSI_CaseSensitivity% "!_GSSI_CurrentWindow!" NEQ "!_GSSI_CurrentWindowResult!" ( if %_GSSI_Search_Window_len% EQU 1 ( GoTo :GetSubstringIndex-substring-end ) else ( set /a _GSSI_Search_Window_len=%_GSSI_Search_Window_len%/2 ) ) else ( set /a _GSSI_Index=%_GSSI_Index%+%_GSSI_Search_Window_len% )
GoTo :GetSubstringIndex-substring-loop 
:GetSubstringIndex-substring-end
:GetSubstringIndex-end
if not defined _GSSI_Result ( set /a _GSSI_Result=%_GSSI_Index% ) else ( if %_GSSI_Index% LSS %_GSSI_Result% set /a _GSSI_Result=%_GSSI_Index% )
set /a _GSSI_Delimiter.index+=1
IF %_GSSI_Delimiter.index% LEQ %_GSSI_Delimiter.ubound% GoTo :GetSubstringIndex-loop
endlocal & set /a _GSSI_Index=%_GSSI_Index% & if "[%_GSSI_Output%]" NEQ "[]" set /a %_GSSI_Output%=%_GSSI_Index%
Call :ClearVariablesByPrefix %_GetSubstringIndex_prefix% _GetSubstringIndex_prefix & exit /b %_GSSI_Index% 

shodan
Posts: 89
Joined: 01 May 2023 01:49

Re: Fast and robust :GetSubstringIndex :ReplaceString :CreateRandomStringPS functions !

#12 Post by shodan » 10 Jun 2024 19:14

Demonstration of the latest getsubstring demo function

https://youtu.be/ssmgLOfvWSY
https://youtu.be/HZ7tgGAgglQ

Code: Select all

::Usage Call :GetSubstringTestHelper [GetSubstringTestHelper arguments]
:GetSubstringTestHelper
set "_GetSubstringTestHelper_prefix=_GSTH"
setlocal enabledelayedexpansion
set "_GSTH_Space=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   "
call :len _GSTH_Space _GSTH_Space_len
echo _GSTH_Space_len%_GSTH_Space_len%
set "_GSTH_OutputArray=%~1" & shift
for /f "tokens=1,2 delims=-" %%a in ("%~1") do ( set /a _GSTH_Min=%%a & set /a _GSTH_Max=%%b 2>nul ) & shift
if not defined _GSTH_Max ( set /a _GSTH_ActualCount=%_GSTH_Min% ) else ( call :rnd _GSTH_ActualCount %_GSTH_Min% %_GSTH_Max% )
set "%_GSTH_OutputArray%.comment=%~1" & shift
set /a _GSTH_Base.ubound=0 & set /a _GSTH_Delimiters.ubound=-1
GoTo :GetSubstringTestHelper-base-args
:GetSubstringTestHelper-args
if /i "[%~1]" EQU "[BASE]" ( set /a _GSTH_Base.ubound+=1 & shift & GoTo :GetSubstringTestHelper-base-args )
if /i "[%~1]" EQU "[DELIMITER]" ( set /a _GSTH_Delimiters.ubound+=1 & set /a _GSTH_Delimiters[!_GSTH_Delimiters.ubound!].IndexOffset=0 & set /a _GSTH_Delimiters[!_GSTH_Delimiters.ubound!].Repeat=0 & shift & GoTo :GetSubstringTestHelper-delimiter-args )
GoTo :GetSubstringTestHelper-args-skip
:GetSubstringTestHelper-base-args
if defined %~1 ( set "_GSTH_Base[%_GSTH_Base.ubound%]=%~1" & Call :len _GSTH_Base[%_GSTH_Base%] _GSTH_Base[%_GSTH_Base%].len & shift & GoTo :GetSubstringTestHelper-args )
if /i "[%~1]" EQU "[LITERAL]" ( set "_GSTH_Base[%_GSTH_Base.ubound%]=%~2" & shift & shift & GoTo :GetSubstringTestHelper-args )
for /f "tokens=1,2 delims=-" %%a in ("%~2") do ( set /a _GSTH_Min=%%a & set /a _GSTH_Max=%%b 2>nul )
if not defined _GSTH_Max ( set /a _GSTH_Base[%_GSTH_Base.ubound%].len=%_GSTH_Min% ) else ( call :rnd _GSTH_Base[%_GSTH_Base.ubound%].len %_GSTH_Min% %_GSTH_Max% )
Call :CreateRandomStringPS %~1 !_GSTH_Base[%_GSTH_Base.ubound%].len! _GSTH_Base[%_GSTH_Base.ubound%] & shift & shift 
if "[%~1]" NEQ "[]" ( GoTo :GetSubstringTestHelper-args ) else ( GoTo :GetSubstringTestHelper-args-skip )
:GetSubstringTestHelper-delimiter-args
if /i "[%~1]" EQU "[INVERTPOSITION]" ( set "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].InvertPosition=true" & shift & GoTo :GetSubstringTestHelper-delimiter-args )
if /i "[%~1]" EQU "[INDEXOFFSET]" ( set /a "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].IndexOffset=%~2" & shift & shift & GoTo :GetSubstringTestHelper-delimiter-args )
if /i "[%~1]" EQU "[REPEAT]" ( set "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].Repeat=%~2" & shift & shift & GoTo :GetSubstringTestHelper-delimiter-args )
if /i "[%~1]" EQU "[LITERAL]" ( set "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%]=%~2" & shift & shift & GoTo :GetSubstringTestHelper-args )
if defined %~1 ( set "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%]=!%~1!" & Call :len _GSTH_Delimiters[%_GSTH_Delimiters_ubound%] _GSTH_Delimiters[%_GSTH_Delimiters.ubound%].len & shift & GoTo :GetSubstringTestHelper-args)
if "[!%~1.ubound!]" EQU "[]" GoTo :GetSubstringTestHelper-delimiter-array-skip
if defined %~1.ubound ( set /a _GSTH_Delimiters.ubound-=1 & for /l %%a in (0,1,!%~1.ubound!) do ( set /a _GSTH_Delimiters.ubound+=1 & Call :CopyObject %~1[%%a] _GSTH_Delimiters[%_GSTH_Delimiters.ubound%] ) )
shift & GoTo :GetSubstringTestHelper-args 
:GetSubstringTestHelper-delimiter-array-skip
for /f "tokens=1,2 delims=-" %%a in ("%~2") do ( set /a _GSTH_Min=%%a & set /a _GSTH_Max=%%b 2>nul )
if not defined _GSTH_Max ( set /a _GSTH_Delimiters[%_GSTH_Delimiters.ubound%].len=%_GSTH_Min% ) else ( call :rnd _GSTH_Delimiters[%_GSTH_Delimiters.ubound%].len %_GSTH_Min% %_GSTH_Max% )
set "_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].setting=%~1"
Call :CreateRandomStringPS !_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].setting! !_GSTH_Delimiters[%_GSTH_Delimiters.ubound%].len! _GSTH_Delimiters[%_GSTH_Delimiters.ubound%] & shift & shift 
if "[%~1]" NEQ "[]" GoTo :GetSubstringTestHelper-args
:GetSubstringTestHelper-args-skip
set /a _GSTH_index=0
:GetSubstringTestHelper-loop
set /a _GSTH_Base.index=0
:GetSubstringTestHelper-base-loop
set /a _GSTH_Delimiters.index=0
set "_GSTH_CurrentInputPointer=_GSTH_Base[%_GSTH_Base.index%]"
:GetSubstringTestHelper-delimiter-loop
if defined _GSTH_Delimiters[%_GSTH_Delimiters.index%].InvertPosition ( set /a _GSTH_Delimiter_Position=%_GSTH_ActualCount%-%_GSTH_index%+!_GSTH_Delimiters[%_GSTH_Delimiters.index%].IndexOffset!-1 ) else ( set /a _GSTH_Delimiter_Position=%_GSTH_index%+!_GSTH_Delimiters[%_GSTH_Delimiters.index%].IndexOffset! )
if %_GSTH_Delimiter_Position% LSS 0 GoTo :GetSubstringTestHelper-delimiter-loop-skip
Call :ReplaceString %_GSTH_CurrentInputPointer% %_GSTH_OutputArray%[%_GSTH_index%] REPEAT "!_GSTH_Delimiters[%_GSTH_Delimiters.index%].Repeat!" LEN !_GSTH_Delimiters[%_GSTH_Delimiters.index%].len! %_GSTH_Delimiter_Position% _GSTH_Delimiters[%_GSTH_Delimiters.index%]
echo.%_GSTH_OutputArray%[%_GSTH_index%]=!%_GSTH_OutputArray%[%_GSTH_index%]!
Call :GetSubstringIndex OUTPUT _GSTH_Substring_Result %_GSTH_OutputArray%[%_GSTH_index%] _GSTH_Delimiters[%_GSTH_Delimiters.index%] "" 
echo.%_GSTH_OutputArray%[%_GSTH_index%]=!_GSTH_Space:~0,%_GSTH_Substring_Result%!!_GSTH_Delimiters[%_GSTH_Delimiters.index%]!
:GetSubstringTestHelper-delimiter-loop-skip
set "_GSTH_CurrentInputPointer=%_GSTH_OutputArray%[%_GSTH_index%]" & set /a _GSTH_Delimiters.index+=1
if %_GSTH_Delimiters.index% LEQ %_GSTH_Delimiters.ubound% GoTo :GetSubstringTestHelper-delimiter-loop
set /a _GSTH_index+=1
if %_GSTH_Base.index% LEQ %_GSTH_Base.ubound% ( set /a "_GSTH_Base.index+=1" ) else ( set /a "_GSTH_Base.index=0" )
if %_GSTH_index% LSS %_GSTH_ActualCount% GoTo :GetSubstringTestHelper-loop
set /a %_GSTH_OutputArray%.ubound=%_GSTH_ActualCount%
set /a _GSTH_index=0
:GetSubstringTestHelper-test-loop
set /a _GSTH_index+=1
if %_GSTH_index% LSS !%_GSTH_OutputArray%.ubound! GoTo :GetSubstringTestHelper-test-loop
for /F "delims=" %%a in ('set %_GSTH_OutputArray%') do (
	endlocal
	set "%%a"
	)
Call :ClearVariablesByPrefix %_GetSubstringTestHelper_prefix% _GetSubstringTestHelper
GoTo :EOF

Post Reply