Page 1 of 1

string that is related with delims=, i need right strings

Posted: 26 Aug 2017 08:57
by nnnmmm

Code: Select all

LET AA$="12 345/67890"
CALL www(AA$,"/",BB$)
PRINT BB$
-----------------------
BB$ becomes 67890


how can i write a script like this?
would you point me to a site?
length of AA$ is totally arbitray, please do not make any %x:~7,6% kind of thing

Re: string that is related with delims=, i need right strings

Posted: 26 Aug 2017 09:20
by Compo
Possibly:

Code: Select all

@Echo Off

Set "AA$=12 345/67890"
Set "BB$=%AA$:*/=%
Echo %BB$%

Timeout -1

Re: string that is related with delims=, i need right strings

Posted: 26 Aug 2017 09:21
by aGerman
Seems you want to get the 2nd token delimited by a slash.

Code: Select all

@echo off
set "aa=12 345/67890"
for /f "tokens=2 delims=/" %%i in ("%aa%") do set "bb=%%i"
echo %bb%
pause


Using a function-like syntax:

Code: Select all

@echo off
set "aa=12 345/67890"
call :www aa "/" bb
echo %bb%
pause
exit /b

:www
setlocal EnableDelayedExpansion
for /f "tokens=2 delims=%~2" %%i in ("!%~1!") do (
  endlocal
  set "%~3=%%i"
  exit /b
)


Steffen

Re: string that is related with delims=, i need right strings

Posted: 26 Aug 2017 12:23
by nnnmmm

Code: Select all

LET AA$="1/2 3/4/5/67890"
CALL www(AA$,"/",BB$)
PRINT BB$
-----------------------
BB$ becomes 67890


my sincere apology, it was supposed to be read from the right side of the string... i think it is related to LPOSR in basic.

Code: Select all

c:\abc def\12\mdd\abc.exe

i need abc.exe to be read from a full pathname string.

Re: string that is related with delims=, i need right strings

Posted: 26 Aug 2017 13:20
by aGerman
You want to extract the filename out of a path?

Code: Select all

for %%i in ("c:\abc def\12\mdd\abc.exe") do set "fname=%%~nxi"

Steffen

Re: string that is related with delims=, i need right strings

Posted: 26 Aug 2017 23:38
by nnnmmm
>You want to extract the filename out of a path?
no, full path names + options and things are already there for executions, but the paths are too long to display with echo, and directory names dont tell much about anything in general.

only file names and their options are good enough to tell their properties without editing each title manually as to what they are.

and a whole menu is not about files, it is mixed with many different things.

so i hope to know the exact extraction of a string in this case, from a distinct maker to the end.

Re: string that is related with delims=, i need right strings

Posted: 27 Aug 2017 05:03
by aGerman
There is no "official" way in batch to extract a token from the end of a string. If the number of tokens that are delimited by a certain character is always the same you can use a FOR /F loop. If that isn't the case it's getting complicated. Batch is very limited so we try to use any undocumented side effect and undefined behaviour. No idea where to sort in the following technique that is based on the string replacement syntax but uses command concatenation inside.

Code: Select all

@echo off
set "aa=1/2 3/4/5/67890"

set "bb=%aa:/=" & set "bb=%"

echo %bb%
pause

Steffen

Re: string that is related with delims=, i need right strings

Posted: 29 Aug 2017 02:49
by nnnmmm
write again

Re: string that is related with delims=, i need right strings

Posted: 29 Aug 2017 03:25
by nnnmmm

Code: Select all

@echo off
set aa=1/2 3/4/5/67890
set bb=%aa:/= & set bb=%
echo %bb%
it worked well.

@echo off
set mark=/

set aa=1/2 3/4/5/67890
set bb=%aa:%mark%= & set bb=%
echo %bb%

how can i move mark out of it ?

Re: string that is related with delims=, i need right strings

Posted: 29 Aug 2017 07:41
by Aacini

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "aa=1/2 3/4/5/67890"
set "mark=/"

for %%b in ("!aa:%mark%=" "!") do set "bb=%%~b"

echo %bb%

Antonio

Re: string that is related with delims=, i need right strings

Posted: 05 Sep 2017 01:48
by nnnmmm

Code: Select all

@ECHO OFF
SETLOCAL
SET IN1=1/2 3/4/5S D6  7890
SET IN1=1234567890
SET IN2=5

CALL "LIB-STRING1.BAT" GET_STR_PIVOT_TO_END1 IN1 IN2 ANS
ECHO %IN1% %ANS%
PAUSE

i am stuck here, why am i not getting the answer "67890"


Code: Select all

LIB-STRING1.BAT has
CALL :%1 %*
EXIT /B

:GET_STR_PIVOT_TO_END1
(@ECHO OFF
 Setlocal EnableDelayedExpansion
   SET "INP=!%~2!"
   SET "PIVOT=!%~3!"
   FOR %%U IN ("!INP:PIVOT=" "!") DO SET "ANS=%%~U"
)
(Endlocal
   SET %~4=%ANS%
)
EXIT /B

Re: string that is related with delims=, i need right strings

Posted: 05 Sep 2017 12:20
by Squashman
You are missing percent symbols around the variable PIVOT and there is no need to put your function on a parenthesized block.

Re: string that is related with delims=, i need right strings

Posted: 05 Sep 2017 17:59
by nnnmmm

Code: Select all

%PIVOT% in FOR %%U IN ("!INP:%PIVOT%=" "!") DO SET "ANS=%%~U" 

interferes with Setlocal EnableDelayedExpansion