Page 1 of 1

Batch string manipulation

Posted: 02 Jul 2020 06:45
by issenlos
Hey my friends,
i'm a newbie to Batch programming (and do not want to spend too much time in it as i dunnot really use it regularly). Maybe soneome of you Pro's can help me out with some quick lines....

I got an url string, of which i iwant to extract a specific string because i want to build a filename of it usinf with ffmpeg. The idea is that my script asks me for an URL and then builds the filename of this string to run ffmpeg

the filenames always look like this:

https://fdsdfasf.stream.fsdafsdafsda.com/live-hls/amlst:evilevi_-sd-ebc76db271adfc05712A=.m3u8

where I always want to extract the sting between the "/amlst:" and the -sd- (whis is always there but positions are not always the same)

Is it possible to find out at which position these two strings are and then extract the string between it? If not with Batch itself - maybe with another tool i can inculde in my batch script?

would be really great if anyone can help me out with this.....
thanks so much in advance!!!

Re: Batch string manipulation

Posted: 02 Jul 2020 11:47
by Aacini
Something like this?

Code: Select all

@echo off
setlocal

rem Ask for the URL
rem set /P "url=Enter URL: "
rem Just for testing:
set "url=https://fdsdfasf.stream.fsdafsdafsda.com/live-hls/amlst:evilevi_-sd-ebc76db271adfc05712A=.m3u8"

rem Remove from begining up to "/amlst:" part
set "filename=%url:*/amlst:=%"
rem Remove from "-sd-" part up to string end
set "filename=%filename:-sd-=" & rem "%"

echo "%filename%"
Antonio