Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 544 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"delims=#+#" - more then 1 character as delimiter

#1
Is it possible to define a delimiter which is not limited to 1 character? Based on the title's example, I would like to define my separator as e.g.
'#+#'. Textfiles/lines can contain both characters, but there is very little chance you'll come across that particular substring/text combo.
Reply

#2
No, you can not use a *string* as a delimiter in the `delims=` clause. Of course you can include the string, but it will be handled as a set of separate characters that will be used as delimiters, not as a delimiter string.

If you really need to split on a string, the fastest approach could be to replace the *delimiter string* by a character not included in the data and use this character as delimiter

<!-- language: lang-dos -->

@echo off
setlocal enableextensions disabledelayedexpansion

for /f "delims=" %%a in ("this is a +test!! #+# of string #splitting#") do (
set "buffer=%%a"
setlocal enabledelayedexpansion
(for /f "tokens=1,2 delims=¬" %%b in ("!buffer:#+#=¬!") do (
endlocal
echo full line : [%%a]
echo first token : [%%b]
echo second token : [%%c]
)) || if "!!"=="" endlocal
)

**Note**: The `setlocal enabledelayedexpansion` is needed to be able to read the variable changed inside the `for` loop retrieving the data (here simulated directly including a string). Then, inside the `for` loop that tokenizes the readed line, delayed expansion is disabled to avoid problems with the `!` characters (if delayed expansion is active, they will be consumed by the parser). This is the reason for the `endlocal` inside the loop.

As we are doing a string replacement and it is possible to end with a string composed of only delimiters, it is possible that the `do` clause of the inner `for` will not be executed, so the final `if` is included to ensure that the `enabledelayedexpansion` is cancelled.
Reply

#3
I recently discovered an interesting trick that allows to use a multi-character string as delimiter to split a larger string in a very simple way; the method does not use any `for` command, but perform the split _in just one line!_ Here it is:

@echo off

set "str=this is a +test!! #+# of string #splitting#"

set "first=%str:#+#=" & set "last=%"

echo full line : [%str%]
echo first token : [%first%]
echo last token : [%last%]

This method also allows to split a large string in several parts and store _all of them_ in an array. Further details at

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through